Search in sources :

Example 1 with CharsBuilder

use of suite.primitive.Chars.CharsBuilder in project suite by stupidsing.

the class FactorizeResult method unparse.

public String unparse() {
    CharsBuilder cb = new CharsBuilder();
    cb.append(pre);
    unparse(cb, node);
    cb.append(post);
    return cb.toChars().toString();
}
Also used : CharsBuilder(suite.primitive.Chars.CharsBuilder)

Example 2 with CharsBuilder

use of suite.primitive.Chars.CharsBuilder in project suite by stupidsing.

the class SmtpSslGmail method convert.

private static String convert(char[] salt, String in0, ChrChr_Int f) {
    CharsBuilder cb = new CharsBuilder();
    char[] in1 = in0.toCharArray();
    for (int i = 0; i < in1.length; i++) {
        int a = f.apply(in1[i], salt[i % salt.length]);
        while (a < 32) a += 128 - 32;
        while (128 < a) a -= 128 - 32;
        cb.append((char) a);
    }
    return cb.toChars().toString();
}
Also used : CharsBuilder(suite.primitive.Chars.CharsBuilder)

Example 3 with CharsBuilder

use of suite.primitive.Chars.CharsBuilder in project suite by stupidsing.

the class As method utf8decode.

public static Outlet<Chars> utf8decode(Outlet<Bytes> bytesOutlet) {
    Source<Bytes> source = bytesOutlet.source();
    return Outlet.of(new Source<>() {

        private BytesBuilder bb = new BytesBuilder();

        public Chars source() {
            Chars chars;
            while ((chars = decode()).size() == 0) {
                Bytes bytes = source.source();
                if (bytes != null)
                    bb.append(bytes);
                else if (bb.size() == 0)
                    return null;
                else
                    return Fail.t();
            }
            return chars;
        }

        private Chars decode() {
            Bytes bytes = bb.toBytes();
            CharsBuilder cb = new CharsBuilder();
            int s = 0;
            while (s < bytes.size()) {
                int b0 = Byte.toUnsignedInt(bytes.get(s++));
                int ch, e;
                if (b0 < 0x80) {
                    ch = b0;
                    e = s;
                } else if (b0 < 0xE0) {
                    ch = b0 & 0x1F;
                    e = s + 1;
                } else if (b0 < 0xF0) {
                    ch = b0 & 0x0F;
                    e = s + 2;
                } else if (b0 < 0xF8) {
                    ch = b0 & 0x07;
                    e = s + 3;
                } else if (b0 < 0xFC) {
                    ch = b0 & 0x03;
                    e = s + 4;
                } else if (b0 < 0xFE) {
                    ch = b0 & 0x01;
                    e = s + 5;
                } else
                    throw new RuntimeException();
                if (e <= bytes.size()) {
                    while (s < e) {
                        int b = Byte.toUnsignedInt(bytes.get(s++));
                        if ((b & 0xC0) == 0x80)
                            ch = (ch << 6) + (b & 0x3F);
                        else
                            Fail.t();
                    }
                    cb.append((char) ch);
                } else
                    break;
            }
            bb = new BytesBuilder();
            bb.append(bytes.range(s));
            return cb.toChars();
        }
    });
}
Also used : Bytes(suite.primitive.Bytes) CharsBuilder(suite.primitive.Chars.CharsBuilder) Chars(suite.primitive.Chars) BytesBuilder(suite.primitive.Bytes.BytesBuilder)

Example 4 with CharsBuilder

use of suite.primitive.Chars.CharsBuilder in project suite by stupidsing.

the class ChrOutlet method toList.

public CharsBuilder toList() {
    CharsBuilder list = new CharsBuilder();
    char c;
    while ((c = next()) != ChrFunUtil.EMPTYVALUE) list.append(c);
    return list;
}
Also used : CharsBuilder(suite.primitive.Chars.CharsBuilder)

Example 5 with CharsBuilder

use of suite.primitive.Chars.CharsBuilder in project suite by stupidsing.

the class ChrOutlet method toListMap.

public <K> ChrObjMap<CharsBuilder> toListMap(Chr_Chr valueFun) {
    ChrObjMap<CharsBuilder> map = new ChrObjMap<>();
    char c;
    while ((c = next()) != ChrFunUtil.EMPTYVALUE) map.computeIfAbsent(c, k_ -> new CharsBuilder()).append(valueFun.apply(c));
    return map;
}
Also used : CharsBuilder(suite.primitive.Chars.CharsBuilder) ChrObjMap(suite.primitive.adt.map.ChrObjMap)

Aggregations

CharsBuilder (suite.primitive.Chars.CharsBuilder)5 Bytes (suite.primitive.Bytes)1 BytesBuilder (suite.primitive.Bytes.BytesBuilder)1 Chars (suite.primitive.Chars)1 ChrObjMap (suite.primitive.adt.map.ChrObjMap)1