src/main/java/puhao/simple/msword/generator/parse/ParsedXWPFParagraph.java
private static int extractVariable(String text, int i, StringBuilder sb) {
        char c = ' ';
        boolean dotFound = false;
        for(; i < text.length(); i++){
            c = text.charAt(i);

            if(c == ' ' || c == '\t'){
                throw new IllegalArgumentException("Variable name must not contain space character nor tab character. " +
                        "The supported char for variable name are: "+PlaceholderVariable.SUPPORTED_CHAR_DESC+". Paragraph: " + text);
            }

            if(c == '.'){
                if(dotFound){
                    throw new IllegalArgumentException("Invalid variable, for one variable, only one dot character can be used to identify the object. Paragraph: " + text);
                }else{
                    dotFound = true;
                }
            }

            sb.append(c);

            if(c == MSWordExporter.BRACES_R){
                if(sb.length() == 0){
                    throw new IllegalArgumentException("Variable must have a name, like ${age}. The supported char for variable name are: "
                            +PlaceholderVariable.SUPPORTED_CHAR_DESC+". Paragraph: " + text);
                }
                return i;
            }else if(PlaceholderVariable.isInvalidChar(c)){
                throw new IllegalArgumentException("Variable name contain invalid character (only support "+
                        PlaceholderVariable.SUPPORTED_CHAR_DESC+") or variable missing right braces at index "+i+" of paragraph: " + text);
            }
        }
        throw new IllegalArgumentException("Variable missing right braces of paragraph: " + text);
    }
/**
     * The start index i is first character after {.
     * If the variable is ${abc}, then the index i is point to char 'a' in this string.
     * @param text
     * @param i
     * @param sb
     * @return
     */
The start index i is first character after {.
If the variable is ${abc}, then the index i is point to char 'a' in this string.
The start index i is first character after { . If the variable is $ { abc } then the index i is point to char ' a ' in this string .
private static int extractVariable(String text, int i, StringBuilder sb) {
        char c = ' ';
        boolean dotFound = false;
        for(; i < text.length(); i++){
            c = text.charAt(i);
            if(c == ' ' || c == '\t'){
                throw new IllegalArgumentException("Variable name must not contain space character nor tab character. " +
                        "The supported char for variable name are: "+PlaceholderVariable.SUPPORTED_CHAR_DESC+". Paragraph: " + text);
            }
            if(c == '.'){
                if(dotFound){
                    throw new IllegalArgumentException("Invalid variable, for one variable, only one dot character can be used to identify the object. Paragraph: " + text);
                }else{
                    dotFound = true;
                }
            }
            sb.append(c);
            if(c == MSWordExporter.BRACES_R){
                if(sb.length() == 0){
                    throw new IllegalArgumentException("Variable must have a name, like ${age}. The supported char for variable name are: "
                            +PlaceholderVariable.SUPPORTED_CHAR_DESC+". Paragraph: " + text);
                }
                return i;
            }else if(PlaceholderVariable.isInvalidChar(c)){
                throw new IllegalArgumentException("Variable name contain invalid character (only support "+
                        PlaceholderVariable.SUPPORTED_CHAR_DESC+") or variable missing right braces at index "+i+" of paragraph: " + text);
            }
        }
        throw new IllegalArgumentException("Variable missing right braces of paragraph: " + text);
    }
private static int extractVariable ( String text , int i , StringBuilder sb ) { char c = ' ' ; boolean dotFound = false ; for ( ; i < text . length ( ) ; i ++ ) { c = text . charAt ( i ) ; if ( c == ' ' || c == '\t' ) { throw new IllegalArgumentException ( "Variable name must not contain space character nor tab character. " + "The supported char for variable name are: " + PlaceholderVariable . SUPPORTED_CHAR_DESC + ". Paragraph: " + text ) ; } if ( c == '.' ) { if ( dotFound ) { throw new IllegalArgumentException ( "Invalid variable, for one variable, only one dot character can be used to identify the object. Paragraph: " + text ) ; } else { dotFound = true ; } } sb . append ( c ) ; if ( c == MSWordExporter . BRACES_R ) { if ( sb . length ( ) == 0 ) { throw new IllegalArgumentException ( "Variable must have a name, like ${age}. The supported char for variable name are: " + PlaceholderVariable . SUPPORTED_CHAR_DESC + ". Paragraph: " + text ) ; } return i ; } else if ( PlaceholderVariable . isInvalidChar ( c ) ) { throw new IllegalArgumentException ( "Variable name contain invalid character (only support " + PlaceholderVariable . SUPPORTED_CHAR_DESC + ") or variable missing right braces at index " + i + " of paragraph: " + text ) ; } } throw new IllegalArgumentException ( "Variable missing right braces of paragraph: " + text ) ; }
The start index i is first character after {.
The start index i is first character after { .