device_option_normalize_name
strips non-alnum and lowercases
This commit is contained in:
parent
14126985f3
commit
0a10a8ba59
@ -2,28 +2,20 @@
|
|||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
int device_option_normalize_name(const char *in, char *outp)
|
int device_option_normalize_name(const char *in, char *outp)
|
||||||
{
|
{
|
||||||
// The output is always shorter, so `outp=in`
|
// The output is always shorter, so `outp=in`
|
||||||
// colour_correction_matrix => ColourCorrectionMatrix
|
// colour_correction_matrix => colourcorrectionmatrix
|
||||||
// Colour Correction Matrix => ColourCorrectionMatrix
|
// Colour Correction Matrix => colourcorrectionmatrix
|
||||||
// ColourCorrectionMatrix => ColourCorrectionMatrix
|
// ColourCorrectionMatrix => colourcorrectionmatrix
|
||||||
|
|
||||||
char *out = outp;
|
char *out = outp;
|
||||||
bool upper = true;
|
|
||||||
|
|
||||||
while (*in) {
|
while (*in) {
|
||||||
if (isalnum(*in)) {
|
if (isalnum(*in)) {
|
||||||
if (upper) {
|
*out++ = tolower(*in++);
|
||||||
*out++ = toupper(*in++);
|
|
||||||
upper = false;
|
|
||||||
} else {
|
|
||||||
*out++ = *in++;
|
|
||||||
}
|
|
||||||
} else if (isprint(*in)) {
|
|
||||||
upper = true;
|
|
||||||
while (*++in && isprint(*in) && !isalnum(*in));
|
|
||||||
} else {
|
} else {
|
||||||
in++;
|
in++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user