MCPcopy Index your code
hub / github.com/MapServer/MapServer / msGetClass_String

Function msGetClass_String

mapraster.c:62–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60/************************************************************************/
61
62static int msGetClass_String( layerObj *layer, colorObj *color, const char *pixel_value )
63
64{
65 int i;
66 const char *tmpstr1=NULL;
67 int numitems;
68 char *item_names[4] = { "pixel", "red", "green", "blue" };
69 char *item_values[4];
70 char red_value[8], green_value[8], blue_value[8];
71
72/* -------------------------------------------------------------------- */
73/* No need to do a lookup in the case of one default class. */
74/* -------------------------------------------------------------------- */
75 if((layer->numclasses == 1) && !(layer->class[0]->expression.string)) /* no need to do lookup */
76 return(0);
77
78/* -------------------------------------------------------------------- */
79/* Setup values list for expressions. */
80/* -------------------------------------------------------------------- */
81 numitems = 4;
82 sprintf( red_value, "%d", color->red );
83 sprintf( green_value, "%d", color->green );
84 sprintf( blue_value, "%d", color->blue );
85
86 item_values[0] = (char *)pixel_value;
87 item_values[1] = red_value;
88 item_values[2] = green_value;
89 item_values[3] = blue_value;
90
91/* -------------------------------------------------------------------- */
92/* Loop over classes till we find a match. */
93/* -------------------------------------------------------------------- */
94 for(i=0; i<layer->numclasses; i++) {
95
96 /* Empty expression - always matches */
97 if (layer->class[i]->expression.string == NULL)
98 return(i);
99
100 switch(layer->class[i]->expression.type) {
101
102/* -------------------------------------------------------------------- */
103/* Simple string match */
104/* -------------------------------------------------------------------- */
105 case(MS_STRING):
106 /* trim junk white space */
107 tmpstr1= pixel_value;
108 while( *tmpstr1 == ' ' )
109 tmpstr1++;
110
111 if(strcmp(layer->class[i]->expression.string, tmpstr1) == 0) return(i); /* matched */
112 break;
113
114/* -------------------------------------------------------------------- */
115/* Regular expression. Rarely used for raster. */
116/* -------------------------------------------------------------------- */
117 case(MS_REGEX):
118 if(!layer->class[i]->expression.compiled) {
119 if(ms_regcomp(&(layer->class[i]->expression.regex), layer->class[i]->expression.string, MS_REG_EXTENDED|MS_REG_NOSUB) != 0) { /* compile the expression */

Callers 2

msGetClassFunction · 0.85
msGetClass_FloatRGBFunction · 0.85

Calls 5

msSetErrorFunction · 0.85
msTokenizeExpressionFunction · 0.85
yyparseFunction · 0.85
ms_regcompFunction · 0.70
ms_regexecFunction · 0.70

Tested by

no test coverage detected