You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@any23.apache.org by ansell <gi...@git.apache.org> on 2017/01/07 00:00:07 UTC

[GitHub] any23 pull request #32: Any23-299: Add support for YAML files

Github user ansell commented on a diff in the pull request:

    https://github.com/apache/any23/pull/32#discussion_r95041854
  
    --- Diff: core/src/main/java/org/apache/any23/util/StringUtils.java ---
    @@ -146,31 +149,59 @@ public static String escapeDoubleQuotes(String in) {
         }
     
         /**
    -     * Escapes the <code>in</code> string as <b>JSON</b> string
    -     * to let it being embeddable within a string field.
    +     * Escapes the <code>in</code> string as <b>JSON</b> string to let it being
    +     * embeddable within a string field.
          *
          * @param in string to be escaped.
          * @return escaped string.
          */
         public static String escapeAsJSONString(String in) {
    -        return escapeDoubleQuotes( in.replaceAll("\n", "\\\\n") );
    +        return escapeDoubleQuotes(in.replaceAll("\n", "\\\\n"));
         }
     
         /**
    -     * Builds a string composed of the given char <code>c</code> <code>n</code> times.
    +     * Builds a string composed of the given char <code>c</code> <code>n</code>
    +     * times.
          *
          * @param c char to be multiplied.
          * @param times number of times.
          * @return the string containing the multiplied char.
          */
         public static String multiply(char c, int times) {
    -        if(times <= 0) throw new IllegalArgumentException("Invalid number of times, must be > 0 .");
    +        if (times <= 0) {
    +            throw new IllegalArgumentException("Invalid number of times, must be > 0 .");
    +        }
             final char[] buffer = new char[times];
    -        for(int i = 0; i < times; i++) {
    +        for (int i = 0; i < times; i++) {
                 buffer[i] = c;
             }
             return new String(buffer);
         }
     
    -    private StringUtils() {}
    +    /**
    +     * Changes string with following convention:
    +     * <ul>
    +     * <li>Changes '-' -> '_'
    +     * <li>remove space characters and make first letter word uppercase: 'some
    +     * string' -> 'someString'
    +     * </ul>
    +     *
    +     * @param in
    +     * @return
    +     */
    +    public static String implementJavaNaming(String in) {
    +        in = in.trim()
    +                .replaceAll("-", "_")
    +                .toLowerCase();
    +
    +        if (Pattern.matches("\\S+(\\s+\\S+)+", in)) {
    +            String[] words = in.split("\\s", 2);
    +            in = words[0] + WordUtils.capitalize(words[1]);
    --- End diff --
    
    It may be more useful to iteratively move along all of the spaces in the input string and capitalise, rather than just the first and second words.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---