当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils类代码示例

本文整理汇总了Java中org.parboiled.common.StringUtils的典型用法代码示例。如果您正苦于以下问题:Java StringUtils类的具体用法?Java StringUtils怎么用?Java StringUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringUtils类属于org.parboiled.common包,在下文中一共展示了StringUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: formatLocalDateFromZonedDate

import org.parboiled.common.StringUtils; //导入依赖的package包/类
/**
 * Formats a ZonedDateTime into a string with the given DateTimeFormatter pattern
 * @param date
 * @param formatPattern
 * @return
 */
public static String formatLocalDateFromZonedDate(ZonedDateTime date, String formatPattern) {
    if (date == null) {
        return "";
    }

    ZonedDateTime localDt = date.withZoneSameInstant(Context.getSettings().getTimeZoneId());

    DateTimeFormatter formatter;
    if (StringUtils.isEmpty(formatPattern)) {
        formatter = DEFAULT_FORMAT;
    } else if ("iso".equals(formatPattern.toLowerCase())) {
        formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
    } else {
        formatter = DateTimeFormatter.ofPattern(formatPattern);
    }
    return localDt.format(formatter);
}
 
开发者ID:StallionCMS,项目名称:stallion-core,代码行数:24,代码来源:DateUtils.java

示例2: serialize

import org.parboiled.common.StringUtils; //导入依赖的package包/类
@Override
public void serialize(final VerbatimNode node, final Printer printer) {
    printer.println().print("<pre><code");
    String className = "prettyprint";
    if (!StringUtils.isEmpty(node.getType())) {
        className = className.concat(" " + node.getType());
    }
    printAttribute(printer, "class", className);
    printer.print(">");
    String text = node.getText();
    // print HTML breaks for all initial newlines
    while (text.charAt(0) == '\n') {
        printer.print("<br/>");
        text = text.substring(1);
    }
    printer.printEncoded(text);
    printer.print("</code></pre>");

}
 
开发者ID:microacup,项目名称:microbbs,代码行数:20,代码来源:PrettifyVerbatimSerializer.java

示例3: visit

import org.parboiled.common.StringUtils; //导入依赖的package包/类
@Override
public void visit(OrderedListNode oln) {

    ++listLevel;
    try {
        _buffer.append('\n');
        for (Node child : oln.getChildren()) {
            _buffer.append( StringUtils.repeat('#', listLevel) ).append(' ');
            child.accept(this);
            _buffer.append('\n');
        }
        _buffer.append('\n');
    }finally {
        --listLevel;
    }

}
 
开发者ID:bsorrentino,项目名称:maven-confluence-plugin,代码行数:18,代码来源:ToConfluenceSerializer.java

示例4: findNodeByPath

import org.parboiled.common.StringUtils; //导入依赖的package包/类
/**
 * Returns the node underneath the given parents that matches the given path.
 * See {@link #findNodeByPath(org.parboiled.Node, String)} )} for a description of the path argument.
 * If the given collections of parents is null or empty or no node is found the method returns null.
 *
 * @param parents the parent Nodes to look through
 * @param path    the path to the Node being searched for
 * @return the Node if found or null if not found
 */
public static <V> Node<V> findNodeByPath(List<Node<V>> parents, String path) {
    checkArgNotNull(path, "path");
    if (parents != null && !parents.isEmpty()) {
        int separatorIndex = path.indexOf('/');
        String prefix = separatorIndex != -1 ? path.substring(0, separatorIndex) : path;
        int start = 0, step = 1;
        if (prefix.startsWith("last:")) {
            prefix = prefix.substring(5);
            start = parents.size() - 1;
            step = -1;
        }
        for (int i = start; 0 <= i && i < parents.size(); i += step) {
            Node<V> child = parents.get(i);
            if (StringUtils.startsWith(child.getLabel(), prefix)) {
                return separatorIndex == -1 ? child : findNodeByPath(child, path.substring(separatorIndex + 1));
            }
        }
    }
    return null;
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:30,代码来源:ParseTreeUtils.java

示例5: collectNodesByPath

import org.parboiled.common.StringUtils; //导入依赖的package包/类
/**
 * Collects all nodes underneath the given parents that match the given path.
 * The path is a '/' separated list of node label prefixes describing the ancestor chain of the node to look for
 * relative to the given parent nodes.
 *
 * @param parents    the parent Nodes to look through
 * @param path       the path to the Nodes being searched for
 * @param collection the collection to collect the found Nodes into
 * @return the same collection instance passed as a parameter
 */
public static <V, C extends Collection<Node<V>>> C collectNodesByPath(List<Node<V>> parents, String path,
                                                                      C collection) {
    checkArgNotNull(path, "path");
    checkArgNotNull(collection, "collection");
    if (parents != null && !parents.isEmpty()) {
        int separatorIndex = path.indexOf('/');
        String prefix = separatorIndex != -1 ? path.substring(0, separatorIndex) : path;
        for (Node<V> child : parents) {
            if (StringUtils.startsWith(child.getLabel(), prefix)) {
                if (separatorIndex == -1) {
                    collection.add(child);
                } else {
                    collectNodesByPath(child, path.substring(separatorIndex + 1), collection);
                }
            }
        }
    }
    return collection;
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:30,代码来源:ParseTreeUtils.java

示例6: format

import org.parboiled.common.StringUtils; //导入依赖的package包/类
public String format(InvalidInputError error) {
    if (error == null) return "";

    int len = error.getEndIndex() - error.getStartIndex();
    StringBuilder sb = new StringBuilder();
    if (len > 0) {
        char c = error.getInputBuffer().charAt(error.getStartIndex());
        if (c == Chars.EOI) {
            sb.append("Unexpected end of input");
        } else {
            sb.append("Invalid input '")
                    .append(StringUtils.escape(String.valueOf(c)));
            if (len > 1) sb.append("...");
            sb.append('\'');
        }
    } else {
        sb.append("Invalid input");
    }
    String expectedString = getExpectedString(error);
    if (StringUtils.isNotEmpty(expectedString)) {
        sb.append(", expected ").append(expectedString);
    }
    return sb.toString();
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:25,代码来源:DefaultInvalidInputErrorFormatter.java

示例7: main

import org.parboiled.common.StringUtils; //导入依赖的package包/类
public static void main(String[] args) {
    TimeParser parser = Parboiled.createParser(TimeParser.class);
    
    while (true) {
        System.out.print("Enter a time expression (hh:mm(:ss)?, hh(mm(ss)?)? or h(mm)?, single RETURN to exit)!\n");
        String input = new Scanner(System.in).nextLine();
        if (StringUtils.isEmpty(input)) break;

        ParsingResult<?> result = new RecoveringParseRunner(parser.Time()).run(input);

        System.out.println(input + " = " + result.parseTreeRoot.getValue() + '\n');
        System.out.println(printNodeTree(result) + '\n');

        if (!result.matched) {
            System.out.println(StringUtils.join(result.parseErrors, "---\n"));
        }
    }
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:19,代码来源:Main.java

示例8: main

import org.parboiled.common.StringUtils; //导入依赖的package包/类
public static void main(String[] args) {
    AbcParser parser = Parboiled.createParser(AbcParser.class);

    while (true) {
        System.out.print("Enter an a^n b^n c^n expression (single RETURN to exit)!\n");
        String input = new Scanner(System.in).nextLine();
        if (StringUtils.isEmpty(input)) break;

        ParsingResult<?> result = new ReportingParseRunner(parser.S()).run(input);

        if (!result.parseErrors.isEmpty())
            System.out.println(ErrorUtils.printParseError(result.parseErrors.get(0)));
        else
            System.out.println(printNodeTree(result) + '\n');
    }
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:17,代码来源:Main.java

示例9: getMethodInstructionList

import org.parboiled.common.StringUtils; //导入依赖的package包/类
public static String getMethodInstructionList(MethodNode methodNode) {
    checkArgNotNull(methodNode, "methodNode");
    Printer printer = new NonMaxTextifier();
    TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer);
    methodNode.accept(traceMethodVisitor);
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    printer.print(printWriter);
    printWriter.flush();
    String[] lines = stringWriter.toString().split("\n");
    int lineNr = 0;
    for (int i = 0; i < lines.length; i++) {
        if (!lines[i].startsWith("  @")) {
            lines[i] = String.format("%2d %s", lineNr++, lines[i]);
        }
    }
    return "Method '" + methodNode.name + "':\n" + StringUtils.join(lines, "\n") + '\n';
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:19,代码来源:AsmTestUtils.java

示例10: main

import org.parboiled.common.StringUtils; //导入依赖的package包/类
public static void main(String[] args) {
    TimeParser parser = Parboiled.createParser(TimeParser.class);
    
    while (true) {
        System.out.print("Enter a time expression (hh:mm(:ss)?, hh(mm(ss)?)? or h(mm)?, single RETURN to exit)!\n");
        String input = new Scanner(System.in).nextLine();
        if (StringUtils.isEmpty(input)) break;

        ParsingResult<?> result = new RecoveringParseRunner(parser.time()).run(input);

        System.out.println(input + " = " + result.parseTreeRoot.getValue() + '\n');
        System.out.println(printNodeTree(result) + '\n');

        if (!result.matched) {
            System.out.println(StringUtils.join(result.parseErrors, "---\n"));
        }
    }
}
 
开发者ID:parboiled1,项目名称:parboiled-examples,代码行数:19,代码来源:Main.java

示例11: debugTree

import org.parboiled.common.StringUtils; //导入依赖的package包/类
private static void debugTree(AbcNode node, int level) {
	AbcNode parent = node.getParent();
	if ((level >= DEBUG_LEVEL) && !DEBUG && !node.hasError()
		&& (parent!=null) && !parent.hasError()) return;
	StringBuffer sb = new StringBuffer();
	sb.append(StringUtils.repeat(' ', level * 2));
	sb.append(node.getLabel());
	if (node.hasError())
		sb.append("!E!");
	sb.append(" = '");
	String v = node.getValue();
	if (v.length() > 103) {
		v = v.substring(0, 50) + "..."
			+ v.substring(v.length() - 50)
			+ " (length="+v.length()+")";
	}
	sb.append(v.replaceAll("\n", "<LF>").replaceAll("\r", "<CR>"));
	sb.append("' (" + node.getCharStreamPosition().toString() + ")");
	System.out.println(sb.toString());
	Iterator it = node.getChilds().iterator();
	level++;
	while (it.hasNext()) {
		debugTree((AbcNode) it.next(), level);
	}
}
 
开发者ID:Sciss,项目名称:abc4j,代码行数:26,代码来源:AbcParserAbstract.java

示例12: print

import org.parboiled.common.StringUtils; //导入依赖的package包/类
private void print(Node n) {
  try {
    writer.write(StringUtils.repeat(' ', level * indentation));
    if (n.hasLabel(Labels.SYNONYM)) {
      writer.write(SYNONYM_SYMBOL);
    }
    if (n.hasLabel(Labels.BASIONYM)) {
      writer.write(BASIONYM_SYMBOL);
    }
    writer.write(getTitle.apply(n));
    if (n.hasProperty(NeoProperties.RANK)) {
      writer.write(" [");
      writer.write(Rank.values()[(Integer) n.getProperty(NeoProperties.RANK)].name().toLowerCase());
      if (showIds) {
        writer.write(",");
        writer.write(String.valueOf(n.getId()));
      }
      writer.write("]");
    }
    writer.write("\n");

  } catch (IOException e) {
    Throwables.propagate(e);
  }
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:26,代码来源:TxtPrinter.java

示例13: visit

import org.parboiled.common.StringUtils; //导入依赖的package包/类
public void visit(RefLinkNode refLinkNode) {
    // TODO reference link require implement
    // to expand sentence
    String linkName = printChildrenToString(refLinkNode);
    String url = getRefLinkUrl(refLinkNode.referenceKey, linkName);
    // FIXME how to handle url, if linkName include period character?
    // TODO temporary implementation
    if (candidateSentences.size() == 0) { return; }
    CandidateSentence lastCandidateSentence =
            candidateSentences.get(candidateSentences.size() - 1);
    if (StringUtils.isNotEmpty(url)) {
        lastCandidateSentence.setLink(url);
    } else {
        lastCandidateSentence.setContent(
                lastCandidateSentence.getContent());
    }
}
 
开发者ID:redpen-cc,项目名称:redpen,代码行数:18,代码来源:ToFileContentSerializer.java

示例14: encode

import org.parboiled.common.StringUtils; //导入依赖的package包/类
public static String encode(String string) {
	if (StringUtils.isNotEmpty(string)) {
		for (int i = 0; i < string.length(); i++) {
			if (encode(string.charAt(i)) != null) {
				// we have at least one character that needs encoding, so do
				// it one by one
				StringBuilder sb = new StringBuilder();
				for (i = 0; i < string.length(); i++) {
					char c = string.charAt(i);
					String encoded = encode(c);
					if (encoded != null)
						sb.append(encoded);
					else
						sb.append(c);
				}
				return sb.toString();
			}
		}
		return string;
	} else
		return "";
}
 
开发者ID:asciidocj,项目名称:asciidocj,代码行数:23,代码来源:FastEncoder.java

示例15: checkExpr

import org.parboiled.common.StringUtils; //导入依赖的package包/类
/**
 * Parse the expression into a type and check it against expected values
 *
 * @param expr
 * @param typeSig
 * @param isNullable
 * @param isStatic
 * @throws Exception
 */
private AstNode checkExpr(String expr, String typeSig, boolean isNullable, boolean isStatic) throws Exception {
    FanParserTask task = new FanParserTask(null);
    FantomParser parser = Parboiled.createParser(FantomParser.class, task);
    ParsingResult<AstNode> result = new RecoveringParseRunner<AstNode>(parser.testExpr()).run(expr);
    JOTTester.checkIf("Checking for parsing errors: " + expr, !result.hasErrors(), StringUtils.join(result.parseErrors, "\n"));
    AstNode node = result.parseTreeRoot.getValue();
    FantomParserAstActions.linkNodes(result.valueStack);

    addUsingsToNode(node, testUsings);
    addTypeSlotsToNode(node, task, testSlots);
    task.parseVars(node, null);
    //System.out.println("Node for "+expr+" : ");
    if(!task.getDiagnostics().isEmpty())
    {
        FanLexAstUtils.dumpTree(node, 0);
    }
    JOTTester.checkIf("Checking for Semantic errors: " + expr, task.getDiagnostics().isEmpty(), StringUtils.join(task.getDiagnostics(), "\n"));
    FanResolvedType t = node.getType();
    check(expr, t, typeSig, isNullable, isStatic);
    return node;
}
 
开发者ID:tcolar,项目名称:fantomidemodule,代码行数:31,代码来源:FantomTypesTest.java


注:本文中的org.parboiled.common.StringUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。