MCPcopy Create free account
hub / github.com/creatale/node-dv / stringCompareLexical

Function stringCompareLexical

deps/leptonica/src/sarray2.c:184–214  ·  view source on GitHub ↗

! * \brief stringCompareLexical() * * \param[in] str1 * \param[in] str2 * \return 1 if str1 > str2 lexically; 0 otherwise * * * Notes: * (1) If the lexical values are identical, return a 0, to * indicate that no swapping is required to sort the strings. * */

Source from the content-addressed store, hash-verified

182 * </pre>
183 */
184l_int32
185stringCompareLexical(const char *str1,
186 const char *str2)
187{
188l_int32 i, len1, len2, len;
189
190 PROCNAME("sarrayCompareLexical");
191
192 if (!str1)
193 return ERROR_INT("str1 not defined", procName, 1);
194 if (!str2)
195 return ERROR_INT("str2 not defined", procName, 1);
196
197 len1 = strlen(str1);
198 len2 = strlen(str2);
199 len = L_MIN(len1, len2);
200
201 for (i = 0; i < len; i++) {
202 if (str1[i] == str2[i])
203 continue;
204 if (str1[i] > str2[i])
205 return 1;
206 else
207 return 0;
208 }
209
210 if (len1 > len2)
211 return 1;
212 else
213 return 0;
214}
215
216
217/*----------------------------------------------------------------------*

Callers 1

sarraySortFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected