* msGetFirstLine() * * returns the first line of a given string. * called by getLabelSize functions for calculating * the baseline offsets of labels * * this function was implemented to avoid using the * msSplitString function and its multiple mallocs, as * only one malloc is used here. * * this function can be called if the input isn't a * multiline string, but this wastes a malloc
| 2079 | * multiline string, but this wastes a malloc |
| 2080 | */ |
| 2081 | char* msGetFirstLine(char* text) { |
| 2082 | int firstLineLength=0; /*number of bytes up to first \n character */ |
| 2083 | int glyphLength; |
| 2084 | char glyph[11]; |
| 2085 | const char *textptr=text; |
| 2086 | char *firstLine,*firstLineCur; |
| 2087 | /*loop through glyphs in text*/ |
| 2088 | while((glyphLength=msGetNextGlyph(&textptr,glyph))) { |
| 2089 | if(glyphLength==1 && *glyph=='\n') { /*we've hit the first \n char*/ |
| 2090 | firstLineCur = firstLine = msSmallMalloc(firstLineLength+1); |
| 2091 | |
| 2092 | /*copy the first line into the return array*/ |
| 2093 | while(firstLineLength--) { |
| 2094 | *firstLineCur++ = *text++; |
| 2095 | } |
| 2096 | *firstLineCur='\0'; |
| 2097 | return firstLine; |
| 2098 | } |
| 2099 | /*increment byte count if we haven't hit a \n yet*/ |
| 2100 | firstLineLength+=glyphLength; |
| 2101 | } |
| 2102 | /*no newline found in text*/ |
| 2103 | return msStrdup(text); |
| 2104 | } |
| 2105 | |
| 2106 | /************************************************************************/ |
| 2107 | /* msStrdup() */ |
no test coverage detected