-
-
Save headius/fee2d9ceb7b328347e079cad5cb43b3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isConstantInitial(ByteList byteList) { | |
int c, len; | |
int nlen = byteList.realSize(); | |
Encoding enc = byteList.getEncoding(); | |
if (nlen < 1) return false; | |
int byte0 = byteList.get(0); | |
if (byte0 < 128) return enc.isUpper(byte0); | |
byte[] bytes = byteList.getUnsafeBytes(); | |
int begin = byteList.begin(); | |
int end = begin + nlen; | |
c = StringSupport.preciseLength(enc, bytes, begin, end); | |
if (!StringSupport.MBCLEN_CHARFOUND_P(c)) return false; | |
len = StringSupport.MBCLEN_CHARFOUND_LEN(c); | |
c = StringSupport.codePoint(enc, bytes, begin, end); | |
if (enc.isUnicode()) { | |
if (enc.isUpper(c)) return true; | |
if (enc.isLower(c)) return false; | |
if (enc.isCodeCType(c, UnicodeCodeRange.TITLECASELETTER.getCType())) return true; | |
} else { | |
/* fallback to case-folding */ | |
IntHolder holder = new IntHolder(); | |
holder.value = begin; | |
byte[] fold = new byte[Config.ENC_GET_CASE_FOLD_CODES_MAX_NUM]; | |
int r = enc.mbcCaseFold(Config.CASE_FOLD, bytes, holder, end, fold); | |
if (r > 0 && (r != len || ByteList.memcmp(fold, 0, bytes, begin, r) != 0)) | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment