// Elements returned are still escaped // " " is returned as a glyph static L ocr_parseGlyphs(S s) { new L l; for i over s: if (s.charAt(i) == '\\' && i+1 < l(s)) { // parse escaped character l.add(substring(s, i, i+2)); ++i; } else if (s.charAt(i) == '[') { // parse group int j = i+1; new StringBuilder buf; while (j < l(s) && s.charAt(j) != ']') { if (s.charAt(j) == '\\' && j+1 < l(s)) buf.append(s.charAt(j++)); buf.append(s.charAt(j++)); } l.add(str(buf)); i = j; } else if (s.charAt(i) == '{') { // parse symbol int j = i; new StringBuilder buf; while (j < l(s) && s.charAt(j) != '}') { if (s.charAt(j) == '\\' && j+1 < l(s)) buf.append(s.charAt(j++)); buf.append(s.charAt(j++)); } if (j < l(s)) buf.append(s.charAt(j)); l.add(str(buf)); i = j; } else l.add(substring(s, i, i+1)); ret l; }