Compare with ignore capability
Compare with ignore capability
Compare two character arrays while ignoring some characters.
- Ignore some characters
Segment Element
Variable declaration
- 992: register int *ignore;
Segment Element
Code insertion
-
998: ignore = key->ignore;
- Define CMP_WITH_IGNORE()
-
Macro definition
- Notes
-
In an important interaction, CMP_WITH_IGNORE uses the data structures
generated by LocaleOptz.
In a perverse implementation to support "readability" the CMP_WITH_IGNORE
macro is embedded in the program text at the point of it's first usage.
This divides the code that dispatches on the ignore flag.
- Segment Source
-
1092: #define CMP_WITH_IGNORE(A, B) \
1093: do \
1094: { \
1095: while (texta < lima && textb < limb) \
1096: { \
1097: while (texta < lima && ignore[UCHAR (*texta)]) \
1098: ++texta; \
1099: while (textb < limb && ignore[UCHAR (*textb)]) \
1100: ++textb; \
1101: if (texta < lima && textb < limb) \
1102: { \
1103: if ((A) != (B)) \
1104: { \
1105: diff = (A) - (B); \
1106: break; \
1107: } \
1108: ++texta; \
1109: ++textb; \
1110: } \
1111: \
1112: if (texta == lima && textb < limb && !ignore[UCHAR (*textb)]) \
1113: diff = -1; \
1114: else if (texta < lima && textb == limb \
1115: && !ignore[UCHAR (*texta)]) \
1116: diff = 1; \
1117: } \
1118: \
1119: if (diff == 0) \
1120: { \
1121: while (texta < lima && ignore[UCHAR (*texta)]) \
1122: ++texta; \
1123: while (textb < limb && ignore[UCHAR (*textb)]) \
1124: ++textb; \
1125: \
1126: if (texta == lima && textb < limb) \
1127: diff = -1; \
1128: else if (texta < lima && textb == limb) \
1129: diff = 1; \
1130: } \
1131: /* Relative lengths are meaningless if characters were ignored. \
1132: Handling this case here avoids what might be an invalid length \
1133: comparison below. */ \
1134: if (diff == 0 && texta == lima && textb == limb) \
1135: return 0; \
1136: } \
1137: while (0)
1138: