Skip to content

Commit

Permalink
Showing 2 changed files with 36 additions and 3 deletions.
35 changes: 35 additions & 0 deletions src/org/jcodings/AbstractEncoding.java
Original file line number Diff line number Diff line change
@@ -105,6 +105,41 @@ public void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)
return asciiCaseFoldCodesByString(flag, bytes, p, end);
}

/** onigenc_ascii_only_case_map / onigenc_single_byte_ascii_only_case_map
*/
int asciiOnlyCaseMap(IntHolder flagP, byte[]bytes, IntHolder pp, int end, byte[]to, int toP, int toEnd) {
int toStart = toP;
int flags = flagP.value;

while (pp.value < end && toP < toEnd) {
// specialize for singlebyte ?
int length = length(bytes, pp.value, end);
if (length < 0) return length;
int code = mbcToCode(bytes, pp.value, end) & 0xff;
pp.value += length;

if (code >= 'a' && code <= 'z' && ((flags & Config.CASE_UPCASE) != 0)) {
flags |= Config.CASE_MODIFIED;
code += 'A' - 'a';
} else if (code >= 'A' && code <= 'Z' && ((flags & Config.CASE_DOWNCASE | Config.CASE_FOLD) != 0)) {
flags |= Config.CASE_MODIFIED;
code += 'a' - 'A';
}
to[toP++] = (byte)code;
if ((flags & Config.CASE_TITLECASE) != 0) {
flags ^= (Config.CASE_UPCASE | Config.CASE_DOWNCASE | Config.CASE_TITLECASE);
}
}
flagP.value = flags;
return toP - toStart;
}

@Override
public int caseMap(IntHolder flagP, byte[] bytes, IntHolder pp, int end, byte[] to, int toP, int toEnd) {
return asciiOnlyCaseMap(flagP, bytes, pp, end, to, toP, toEnd);
}


/** onigenc_minimum_property_name_to_ctype
* notably overridden by unicode encodings
*/
4 changes: 1 addition & 3 deletions src/org/jcodings/Encoding.java
Original file line number Diff line number Diff line change
@@ -316,9 +316,7 @@ public final int minLength() {
*
* Oniguruma equivalent: <code>case_map</code>
*/
public int caseMap(IntHolder flagP, byte[]bytes, IntHolder pp, int end, byte[]to, int toP, int toEnd) {
throw new RuntimeException("not implemented");
}
public abstract int caseMap(IntHolder flagP, byte[]bytes, IntHolder pp, int end, byte[]to, int toP, int toEnd);

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

0 comments on commit fe1f964

Please sign in to comment.