Skip to content

Commit fe1f964

Browse files
committedDec 19, 2017
asciiOnlyCaseMap
1 parent ac8e9eb commit fe1f964

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
 

‎src/org/jcodings/AbstractEncoding.java

+35
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,41 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
105105
return asciiCaseFoldCodesByString(flag, bytes, p, end);
106106
}
107107

108+
/** onigenc_ascii_only_case_map / onigenc_single_byte_ascii_only_case_map
109+
*/
110+
int asciiOnlyCaseMap(IntHolder flagP, byte[]bytes, IntHolder pp, int end, byte[]to, int toP, int toEnd) {
111+
int toStart = toP;
112+
int flags = flagP.value;
113+
114+
while (pp.value < end && toP < toEnd) {
115+
// specialize for singlebyte ?
116+
int length = length(bytes, pp.value, end);
117+
if (length < 0) return length;
118+
int code = mbcToCode(bytes, pp.value, end) & 0xff;
119+
pp.value += length;
120+
121+
if (code >= 'a' && code <= 'z' && ((flags & Config.CASE_UPCASE) != 0)) {
122+
flags |= Config.CASE_MODIFIED;
123+
code += 'A' - 'a';
124+
} else if (code >= 'A' && code <= 'Z' && ((flags & Config.CASE_DOWNCASE | Config.CASE_FOLD) != 0)) {
125+
flags |= Config.CASE_MODIFIED;
126+
code += 'a' - 'A';
127+
}
128+
to[toP++] = (byte)code;
129+
if ((flags & Config.CASE_TITLECASE) != 0) {
130+
flags ^= (Config.CASE_UPCASE | Config.CASE_DOWNCASE | Config.CASE_TITLECASE);
131+
}
132+
}
133+
flagP.value = flags;
134+
return toP - toStart;
135+
}
136+
137+
@Override
138+
public int caseMap(IntHolder flagP, byte[] bytes, IntHolder pp, int end, byte[] to, int toP, int toEnd) {
139+
return asciiOnlyCaseMap(flagP, bytes, pp, end, to, toP, toEnd);
140+
}
141+
142+
108143
/** onigenc_minimum_property_name_to_ctype
109144
* notably overridden by unicode encodings
110145
*/

‎src/org/jcodings/Encoding.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,7 @@ public final int minLength() {
316316
*
317317
* Oniguruma equivalent: <code>case_map</code>
318318
*/
319-
public int caseMap(IntHolder flagP, byte[]bytes, IntHolder pp, int end, byte[]to, int toP, int toEnd) {
320-
throw new RuntimeException("not implemented");
321-
}
319+
public abstract int caseMap(IntHolder flagP, byte[]bytes, IntHolder pp, int end, byte[]to, int toP, int toEnd);
322320

323321
/* onigenc_get_right_adjust_char_head / ONIGENC_LEFT_ADJUST_CHAR_HEAD */
324322
public final int rightAdjustCharHead(byte[]bytes, int p, int s, int end) {

0 commit comments

Comments
 (0)
Please sign in to comment.