public static String sourceFileNameToClassName(File baseDir, String filePath) { if (!filePath.endsWith(".java")) { return null; } FastStr path0 = FastStr.of(baseDir.getAbsolutePath()); FastStr path1 = FastStr.of(filePath); if (File.separatorChar != '/') { path0 = path0.replace(File.separatorChar, '/'); path1 = path1.replace(File.separatorChar, '/'); } FastStr ret = path1.afterFirst(path0); if (ret.startsWith("/")) { ret = ret.substr(1); } return ret.replace('/', '.').beforeLast('.').toString(); } }
private String typeDesc(BeanSpec spec) { String root = classDesc(spec.rawType()); List<java.lang.reflect.Type> typeParams = spec.typeParams(); if (typeParams.isEmpty()) { return root; } S.Buffer sb = S.newBuffer("<"); for (java.lang.reflect.Type type : typeParams) { BeanSpec specx = BeanSpec.of(type, null, spec.injector(), typeParamLookup); sb.append(typeDesc(specx)); } sb.append(">"); FastStr str = FastStr.of(root); str = str.take(str.length() - 1).append(sb.toString()).append(";"); return str.toString(); }
/** * Wrapper of {@link String#toLowerCase(java.util.Locale)} but return FastStr type instance * * @param locale the locale * @return a FastStr instance with all characters from this FastStr * be converted into lowercase based on the locale specified */ public FastStr toLowerCase(Locale locale) { String s = toString(); return unsafeOf(s.toLowerCase(locale)); }
static void hashCodeMethodEnd(MethodVisitor mv, int fieldCnt) { FastStr signature; if (fieldCnt < 6) { signature = FastStr.of("Ljava/lang/Object;").times(fieldCnt); } else { signature = FastStr.of("Ljava/lang/Object;").times(5).append("[Ljava/lang/Object;"); } signature = signature.prepend("(").append(")I"); mv.visitMethodInsn(INVOKESTATIC, "org/osgl/Osgl", "hc", signature.toString(), false); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); // just pass any number and have ASM to calculate mv.visitEnd(); }
private void init(CharSequence chars) { final FastStr fs = FastStr.of(chars); final int sz = fs.length(); int last = nextNonSeparator(fs, 0); int pos; while (true) { pos = locateNextStop(fs, last); if (pos < 0 || pos == sz) { FastStr sub = fs.substr(last); if (!sub.isEmpty()) { list.add(sub.toLowerCase()); } break; } FastStr sub = fs.subSequence(last, pos); if (!sub.isEmpty()) { list.add(sub.toLowerCase()); } last = nextNonSeparator(fs, pos); } }
@Override public Void apply(JarFile jarFile, JarEntry jarEntry) throws NotAppliedException, $.Break { try { String fileName = jarEntry.getName(); if (fileName.startsWith("conf/")) { FastStr fs = FastStr.of(fileName).afterFirst('/'); String env = ConfLoader.common(); if (fs.contains('/')) { env = fs.beforeFirst('/').intern(); } Properties p = map.get(env); if (null == p) { p = new Properties(); map.put(env, p); } InputStream is = jarFile.getInputStream(jarEntry); Properties p2 = new Properties(); p2.load(is); p.putAll(p2); } } catch (IOException e) { logger.warn(e, "Unable to load properties file from jar entry %s", jarEntry.getName()); } return null; } };
boolean limited = limit > 0; C.List<FastStr> list = C.newList(); while ((next = indexOf(ch, off)) != -1) { if (!limited || list.size() < limit - 1) { list.add(substr(off, next)); off = next + 1; } else { // last one list.add(substr(off, buf.length)); off = buf.length; break; list.add(substr(off, buf.length)); while (resultSize > 0 && list.get(resultSize - 1).length() == 0) { resultSize--; FastStr[] ssa = new FastStr[len]; for (int i = 0; i < len; ++i) { ssa[i] = unsafeOf(sa[i]);
@Override public boolean apply(JSONSerializer serializer, Object source, String name) { if (source == null) { return true; } // if context path is "$.bar.zee" or "$[0].bar.zee" and name is "foo" // then path should be "bar.zee.foo" String path; FastStr fs = FastStr.of(serializer.getContext().toString()).append('.').append(name); path = fs.substring(fs.indexOf('.') + 1); // skip the first "." return matches(path); }
private static String typeDesc(BeanSpec spec) { String root = classDesc(spec.rawType()); List<java.lang.reflect.Type> typeParams = spec.typeParams(); if (typeParams.isEmpty()) { return root; } StringBuilder sb = S.builder("<"); for (java.lang.reflect.Type type : typeParams) { BeanSpec specx = BeanSpec.of(type, null, spec.injector()); sb.append(typeDesc(specx)); } sb.append(">"); FastStr str = FastStr.of(root); str = str.take(str.length() - 1).append(sb.toString()).append(";"); return str.toString(); } private static String classDesc(Class c) { if (c.isPrimitive()) { c = $.wrapperClassOf(c); } return Type.getDescriptor(c); }
/** * Construct a FastStr from a CharSequence * @param cs the CharSequence instance * @return a FastStr */ public static FastStr of(CharSequence cs) { if (cs instanceof FastStr) { return (FastStr)cs; } return of(cs.toString()); }
/** * Wrapper of {@link String#intern()} * * @return the intern of the string */ @Override public String intern() { return toString().intern(); }
@Override public boolean endsWith(FastStr prefix, int toffset) { int prefixSz = prefix.length(); if (0 == prefixSz) { return true; } int matchStart = length() - toffset; if (matchStart < prefixSz) { return false; } char[] prefixBuf = prefix.buf; for (int i = toInternalId(matchStart - 1), j = prefix.toInternalId(prefixSz - 1); j >= prefix.begin; --i, --j) { char c0 = buf[i]; char c1 = prefixBuf[j]; if (c0 != c1) { return false; } } return true; }
@Override public FastStr append(char... array) { int sz = size(), sz2 = array.length; if (0 == sz2) return this; if (0 == sz) return of(array); char[] newBuf = new char[sz + sz2]; copyTo(newBuf, 0); for (int i = 0; i < sz2; ++i) { newBuf[sz + i] = array[i]; } return new FastStr(newBuf, 0, sz + sz2); }