nashorn/src/jdk/nashorn/api/scripting/Formatter.java
author sundar
Fri, 15 Mar 2013 21:52:40 +0530
changeset 16527 5ba350ebcdbb
parent 16201 889ddb179cdf
child 16784 ba0dd689dd98
permissions -rw-r--r--
8010145: removed workaround "init.js" in nashorn repo Reviewed-by: jlaskey, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16172
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
     1
/*
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
     2
 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
     4
 *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    10
 *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    15
 * accompanied this code).
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    16
 *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    20
 *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    23
 * questions.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    24
 */
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    25
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    26
package jdk.nashorn.api.scripting;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    27
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    28
import java.util.regex.Matcher;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    29
import java.util.regex.Pattern;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    30
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    31
/**
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    32
 * Formatter is a class to get the type conversion between javascript types and
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    33
 * java types for the format (sprintf) method working.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    34
 *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    35
 * <p>In javascript the type for numbers can be different from the format type
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    36
 * specifier. For format type '%d', '%o', '%x', '%X' double need to be
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    37
 * converted to integer. For format type 'e', 'E', 'f', 'g', 'G', 'a', 'A'
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    38
 * integer needs to be converted to double.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    39
 *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    40
 * <p>Format type "%c" and javascript string needs special handling.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    41
 *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    42
 * <p>The javascript date objects can be handled if they are type double (the
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    43
 * related javascript code will convert with Date.getTime() to double). So
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    44
 * double date types are converted to long.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    45
 *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    46
 * <p>Pattern and the logic for parameter position: java.util.Formatter
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    47
 *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    48
 */
16527
5ba350ebcdbb 8010145: removed workaround "init.js" in nashorn repo
sundar
parents: 16201
diff changeset
    49
final class Formatter {
16172
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    50
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16172
diff changeset
    51
    private Formatter() {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16172
diff changeset
    52
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16172
diff changeset
    53
16172
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    54
    /**
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    55
     * Method which converts javascript types to java types for the
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    56
     * String.format method (jrunscript function sprintf).
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    57
     *
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    58
     * @param format a format string
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    59
     * @param args arguments referenced by the format specifiers in format
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    60
     * @return a formatted string
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    61
     */
16527
5ba350ebcdbb 8010145: removed workaround "init.js" in nashorn repo
sundar
parents: 16201
diff changeset
    62
    static String format(final String format, final Object[] args) {
5ba350ebcdbb 8010145: removed workaround "init.js" in nashorn repo
sundar
parents: 16201
diff changeset
    63
        final Matcher m = FS_PATTERN.matcher(format);
16172
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    64
        int positionalParameter = 1;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    65
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    66
        while (m.find()) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    67
            int index = index(m.group(1));
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    68
            boolean previous = isPreviousArgument(m.group(2));
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    69
            char conversion = m.group(6).charAt(0);
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    70
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    71
            // skip over some formats
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    72
            if (index < 0 || previous
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    73
                    || conversion == 'n' || conversion == '%') {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    74
                continue;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    75
            }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    76
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    77
            // index 0 here means take a positional parameter
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    78
            if (index == 0) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    79
                index = positionalParameter++;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    80
            }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    81
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    82
            // out of index, String.format will handle
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    83
            if (index > args.length) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    84
                continue;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    85
            }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    86
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    87
            // current argument
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    88
            Object arg = args[index - 1];
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    89
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    90
            // for date we convert double to long
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    91
            if (m.group(5) != null) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    92
                // convert double to long
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    93
                if (arg instanceof Double) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    94
                    args[index - 1] = ((Double) arg).longValue();
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    95
                }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    96
            } else {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    97
                // we have to convert some types
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    98
                switch (conversion) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
    99
                    case 'd':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   100
                    case 'o':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   101
                    case 'x':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   102
                    case 'X':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   103
                        if (arg instanceof Double) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   104
                            // convert double to long
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   105
                            args[index - 1] = ((Double) arg).longValue();
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   106
                        } else if (arg instanceof String
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   107
                                && ((String) arg).length() > 0) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   108
                            // convert string (first character) to int
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   109
                            args[index - 1] = (int) ((String) arg).charAt(0);
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   110
                        }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   111
                        break;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   112
                    case 'e':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   113
                    case 'E':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   114
                    case 'f':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   115
                    case 'g':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   116
                    case 'G':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   117
                    case 'a':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   118
                    case 'A':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   119
                        if (arg instanceof Integer) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   120
                            // convert integer to double
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   121
                            args[index - 1] = ((Integer) arg).doubleValue();
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   122
                        }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   123
                        break;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   124
                    case 'c':
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   125
                        if (arg instanceof Double) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   126
                            // convert double to integer
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   127
                            args[index - 1] = ((Double) arg).intValue();
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   128
                        } else if (arg instanceof String
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   129
                                && ((String) arg).length() > 0) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   130
                            // get the first character from string
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   131
                            args[index - 1] = (int) ((String) arg).charAt(0);
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   132
                        }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   133
                        break;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   134
                    default:
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   135
                        break;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   136
                }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   137
            }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   138
        }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   139
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   140
        return String.format(format, args);
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   141
    }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   142
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   143
    /**
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   144
     * Method to parse the integer of the argument index.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   145
     *
16527
5ba350ebcdbb 8010145: removed workaround "init.js" in nashorn repo
sundar
parents: 16201
diff changeset
   146
     * @param s string to parse
16172
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   147
     * @return -1 if parsing failed, 0 if string is null, > 0 integer
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   148
     */
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   149
    private static int index(final String s) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   150
        int index = -1;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   151
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   152
        if (s != null) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   153
            try {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   154
                index = Integer.parseInt(s.substring(0, s.length() - 1));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16172
diff changeset
   155
            } catch (final NumberFormatException e) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16172
diff changeset
   156
                //ignored
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16172
diff changeset
   157
            }
16172
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   158
        } else {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   159
            index = 0;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   160
        }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   161
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   162
        return index;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   163
    }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   164
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   165
    /**
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   166
     * Method to check if a string contains '&lt;'. This is used to find out if
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   167
     * previous parameter is used.
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   168
     *
16527
5ba350ebcdbb 8010145: removed workaround "init.js" in nashorn repo
sundar
parents: 16201
diff changeset
   169
     * @param s string to check
16172
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   170
     * @return true if '&lt;' is in the string, else false
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   171
     */
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   172
    private static boolean isPreviousArgument(final String s) {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   173
        return (s != null && s.indexOf('<') >= 0) ? true : false;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   174
    }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   175
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   176
    // %[argument_index$][flags][width][.precision][t]conversion
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   177
    private static final String formatSpecifier =
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   178
            "%(\\d+\\$)?([-#+ 0,(\\<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])";
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   179
    // compiled format string
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   180
    private static final Pattern FS_PATTERN;
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   181
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   182
    static {
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   183
        FS_PATTERN = Pattern.compile(formatSpecifier);
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   184
    }
25c8da53438f 8006181: nashorn script engine does not run jrunscript's initialization script
sundar
parents:
diff changeset
   185
}