! * \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. * */
| 182 | * </pre> |
| 183 | */ |
| 184 | l_int32 |
| 185 | stringCompareLexical(const char *str1, |
| 186 | const char *str2) |
| 187 | { |
| 188 | l_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 | /*----------------------------------------------------------------------* |