/** * Is this a multibyte character from a multibyte encoding? * * @param c * @return whether c is an multibyte char or not */ protected boolean isMultiByteChar(int c) { return encoding.codeToMbcLength(c) != 1; }
/** * Is this a multibyte character from a multibyte encoding? * * @param c * @return whether c is an multibyte char or not */ protected boolean isMultiByteChar(int c) { return encoding.codeToMbcLength(c) != 1; }
public static int encCodelen(ThreadContext context, int c, Encoding enc) { int n = enc.codeToMbcLength(c); if (n == 0) { throw context.runtime.newArgumentError("invalid codepoint " + Long.toHexString(c & 0xFFFFFFFFL) + " in " + enc); } return n; }
private void parseCharClassValEntry(CClassNode cc, CClassNode ascCc, CCStateArg arg) { int len = enc.codeToMbcLength(arg.to); arg.inType = len == 1 ? CCVALTYPE.SB : CCVALTYPE.CODE_POINT; parseCharClassValEntry2(cc, ascCc, arg); // val_entry2: }
private void parseCharClassValEntry(CClassNode cc, CClassNode ascCc, CCStateArg arg) { int len = enc.codeToMbcLength(arg.to); arg.inType = len == 1 ? CCVALTYPE.SB : CCVALTYPE.CODE_POINT; parseCharClassValEntry2(cc, ascCc, arg); // val_entry2: }
public static int encCodelen(ThreadContext context, int c, Encoding enc) { int n = enc.codeToMbcLength(c); if (n == 0) { throw context.runtime.newArgumentError("invalid codepoint " + Long.toHexString(c & 0xFFFFFFFFL) + " in " + enc); } return n; }
public static int codeLength(Encoding enc, int c) { int i = enc.codeToMbcLength(c); return checkCodepointError(i); }
public static int codeLength(Encoding enc, int c) { int i = enc.codeToMbcLength(c); return checkCodepointError(i); }
public static int codeLength(Ruby runtime, Encoding enc, int c) { int n = enc.codeToMbcLength(c); if (n == 0) throw runtime.newRangeError("invalid codepoint " + String.format("0x%x in ", c) + enc.getName()); return n; }
public static int codeLength(Ruby runtime, Encoding enc, int c) { int n = enc.codeToMbcLength(c); if (n == 0) throw runtime.newRangeError("invalid codepoint " + String.format("0x%x in ", c) + enc.getName()); return n; }
public boolean isCodeInCC(Encoding enc, int code) { int len; if (enc.minLength() > 1) { len = 2; } else { len = enc.codeToMbcLength(code); } return isCodeInCCLength(len, code); }
public boolean isCodeInCC(Encoding enc, int code) { int len; if (enc.minLength() > 1) { len = 2; } else { len = enc.codeToMbcLength(code); } return isCodeInCCLength(len, code); }
public static int trNext(final TR tr, Encoding enc) { for (;;) { if ( ! tr.gen ) { return trNext_nextpart(tr, enc); } while (enc.codeToMbcLength( ++tr.now ) <= 0) { if (tr.now == tr.max) { tr.gen = false; return trNext_nextpart(tr, enc); } } if (tr.now < tr.max) { return tr.now; } else { tr.gen = false; return tr.max; } } }
public static int trNext(final TR tr, Encoding enc) { for (;;) { if ( ! tr.gen ) { return trNext_nextpart(tr, enc); } while (enc.codeToMbcLength( ++tr.now ) <= 0) { if (tr.now == tr.max) { tr.gen = false; return trNext_nextpart(tr, enc); } } if (tr.now < tr.max) { return tr.now; } else { tr.gen = false; return tr.max; } } }
private ByteList fromEncodedBytes(Ruby runtime, Encoding enc, int value) { int n; try { n = value < 0 ? 0 : enc.codeToMbcLength(value); } catch (EncodingException ee) { n = 0; } if (n <= 0) throw runtime.newRangeError(this.toString() + " out of char range"); ByteList bytes = new ByteList(n); try { enc.codeToMbc(value, bytes.getUnsafeBytes(), 0); } catch (EncodingException e) { throw runtime.newRangeError("invalid codepoint " + String.format("0x%x in ", value) + enc.getCharsetName()); } bytes.setRealSize(n); return bytes; }
private ByteList fromEncodedBytes(Ruby runtime, Encoding enc, int value) { int n; try { n = value < 0 ? 0 : enc.codeToMbcLength(value); } catch (EncodingException ee) { n = 0; } if (n <= 0) throw runtime.newRangeError(this.toString() + " out of char range"); ByteList bytes = new ByteList(n); try { enc.codeToMbc(value, bytes.getUnsafeBytes(), 0); } catch (EncodingException e) { throw runtime.newRangeError("invalid codepoint " + String.format("0x%x in ", value) + enc.getCharsetName()); } bytes.setRealSize(n); return bytes; }
/** * This looks deceptively like tokadd_mbchar(int, ByteList) but it differs in that it uses * the bytelists encoding and the first parameter is a full codepoint and not the first byte * of a mbc sequence. */ public void tokaddmbc(int codepoint, ByteList buffer) { Encoding encoding = buffer.getEncoding(); int length = encoding.codeToMbcLength(codepoint); buffer.ensure(buffer.getRealSize() + length); encoding.codeToMbc(codepoint, buffer.getUnsafeBytes(), buffer.begin() + buffer.getRealSize()); buffer.setRealSize(buffer.getRealSize() + length); }
/** * This looks deceptively like tokadd_mbchar(int, ByteList) but it differs in that it uses * the bytelists encoding and the first parameter is a full codepoint and not the first byte * of a mbc sequence. */ public void tokaddmbc(int codepoint, ByteList buffer) { Encoding encoding = buffer.getEncoding(); int length = encoding.codeToMbcLength(codepoint); buffer.ensure(buffer.getRealSize() + length); encoding.codeToMbc(codepoint, buffer.getUnsafeBytes(), buffer.begin() + buffer.getRealSize()); buffer.setRealSize(buffer.getRealSize() + length); }
private ByteList convertLFToCRLF(ByteList bs) { if (bs == null || binmode) return bs; byte[] crBytes = crBytes(bs.getEncoding()); byte[] lfBytes = lfBytes(bs.getEncoding()); int p = bs.getBegin(); int end = p + bs.getRealSize(); byte[]bytes = bs.getUnsafeBytes(); Encoding enc = bs.getEncoding(); ByteList result = new ByteList(); int lastWrittenIndex = p; while (p < end) { int c = enc.mbcToCode(bytes, p, end); int cLength = enc.codeToMbcLength(c); if (c == LF) { result.append(bytes, lastWrittenIndex, p - lastWrittenIndex); result.append(crBytes); result.append(lfBytes); lastWrittenIndex = p + cLength; } p += cLength; } if (lastWrittenIndex < end) { result.append(bytes, lastWrittenIndex, end - lastWrittenIndex); } return result; }
private ByteList convertLFToCRLF(ByteList bs) { if (bs == null || binmode) return bs; byte[] crBytes = crBytes(bs.getEncoding()); byte[] lfBytes = lfBytes(bs.getEncoding()); int p = bs.getBegin(); int end = p + bs.getRealSize(); byte[]bytes = bs.getUnsafeBytes(); Encoding enc = bs.getEncoding(); ByteList result = new ByteList(); int lastWrittenIndex = p; while (p < end) { int c = enc.mbcToCode(bytes, p, end); int cLength = enc.codeToMbcLength(c); if (c == LF) { result.append(bytes, lastWrittenIndex, p - lastWrittenIndex); result.append(crBytes); result.append(lfBytes); lastWrittenIndex = p + cLength; } p += cLength; } if (lastWrittenIndex < end) { result.append(bytes, lastWrittenIndex, end - lastWrittenIndex); } return result; }