Exemplo n.º 1
0
        protected internal static bool upToWithQuotes(String s, ParsePosition position,
                                                      java.lang.StringBuffer buffer, char stop, char start)
        {
            int  index = position.getIndex(), length = s.length(), count = 1;
            bool quote = false;

            while (index < length)
            {
                char ch = s.charAt(index++);
                if (ch == '\'')
                {
                    quote = !quote;
                }
                if (!quote)
                {
                    if (ch == stop)
                    {
                        count--;
                    }
                    if (count == 0)
                    {
                        position.setIndex(index);
                        return(true);
                    }
                    if (ch == start)
                    {
                        count++;
                    }
                }
                buffer.append(ch);
            }
            // text.07=Unmatched braces in the pattern
            throw new java.lang.IllegalArgumentException("Unmatched braces in the pattern"); //$NON-NLS-1$
        }
Exemplo n.º 2
0
        /*
         * Gets private field value by reflection.
         *
         * @param fieldName the field name to be set @param target the object which
         * field to be gotten
         *
         * internal static Object getInternalField(String fieldName, Object target) {
         *  Object value = AccessController
         *          .doPrivileged(new PrivilegedAction<Object>() {
         *              public Object run() {
         *                  Object result = null;
         *                  java.lang.reflect.Field field = null;
         *                  try {
         *                      field = target.getClass().getDeclaredField(
         *                              fieldName);
         *                      field.setAccessible(true);
         *                      result = field.get(target);
         *                  } catch (Exception e1) {
         *                      return null;
         *                  }
         *                  return result;
         *              }
         *          });
         *  return value;
         * }*/

        protected internal static bool upTo(String s, ParsePosition position,
                                            java.lang.StringBuffer buffer, char stop)
        {
            int  index = position.getIndex(), length = s.length();
            bool lastQuote = false, quote = false;

            while (index < length)
            {
                char ch = s.charAt(index++);
                if (ch == '\'')
                {
                    if (lastQuote)
                    {
                        buffer.append('\'');
                    }
                    quote     = !quote;
                    lastQuote = true;
                }
                else if (ch == stop && !quote)
                {
                    position.setIndex(index);
                    return(true);
                }
                else
                {
                    lastQuote = false;
                    buffer.append(ch);
                }
            }
            position.setIndex(index);
            return(false);
        }
Exemplo n.º 3
0
        /**
         * Parses the specified string using the rules of this format.
         *
         * @param string
         *            the string to parse.
         * @return the object resulting from the parse.
         * @throws ParseException
         *            if an error occurs during parsing.
         */
        public Object parseObject(String s)  //throws ParseException {
        {
            ParsePosition position = new ParsePosition(0);
            Object        result   = parseObject(s, position);

            if (position.getIndex() == 0)
            {
                // text.1C=Format.parseObject(String) parse failure
                throw new ParseException("Format.parseObject(String) parse failure", position.getErrorIndex()); //$NON-NLS-1$
            }
            return(result);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Parse String with given pattern on ParsePosition to Data object
 /// </summary>
 /// <param name="s"></param>
 /// <param name="pos"></param>
 /// <returns></returns>
 public java.util.Date parse(String s, ParsePosition pos)
 {
     DateTime date = DateTime.ParseExact(s.substring(pos.getIndex()), pattern, CultureInfo.InvariantCulture);
     return new java.util.Date(date.getTime());
 }
Exemplo n.º 5
0
 protected internal static bool upToWithQuotes(String s, ParsePosition position,
         java.lang.StringBuffer buffer, char stop, char start)
 {
     int index = position.getIndex(), length = s.length(), count = 1;
     bool quote = false;
     while (index < length) {
         char ch = s.charAt(index++);
         if (ch == '\'') {
             quote = !quote;
         }
         if (!quote) {
             if (ch == stop) {
                 count--;
             }
             if (count == 0) {
                 position.setIndex(index);
                 return true;
             }
             if (ch == start) {
                 count++;
             }
         }
         buffer.append(ch);
     }
     // text.07=Unmatched braces in the pattern
     throw new java.lang.IllegalArgumentException("Unmatched braces in the pattern"); //$NON-NLS-1$
 }
Exemplo n.º 6
0
 /*
  * Gets private field value by reflection.
  *
  * @param fieldName the field name to be set @param target the object which
  * field to be gotten
  *
 internal static Object getInternalField(String fieldName, Object target) {
     Object value = AccessController
             .doPrivileged(new PrivilegedAction<Object>() {
                 public Object run() {
                     Object result = null;
                     java.lang.reflect.Field field = null;
                     try {
                         field = target.getClass().getDeclaredField(
                                 fieldName);
                         field.setAccessible(true);
                         result = field.get(target);
                     } catch (Exception e1) {
                         return null;
                     }
                     return result;
                 }
             });
     return value;
 }*/
 protected internal static bool upTo(String s, ParsePosition position,
         java.lang.StringBuffer buffer, char stop)
 {
     int index = position.getIndex(), length = s.length();
     bool lastQuote = false, quote = false;
     while (index < length) {
         char ch = s.charAt(index++);
         if (ch == '\'') {
             if (lastQuote) {
                 buffer.append('\'');
             }
             quote = !quote;
             lastQuote = true;
         } else if (ch == stop && !quote) {
             position.setIndex(index);
             return true;
         } else {
             lastQuote = false;
             buffer.append(ch);
         }
     }
     position.setIndex(index);
     return false;
 }
Exemplo n.º 7
0
 /**
  * Parses the specified string using the rules of this format.
  *
  * @param string
  *            the string to parse.
  * @return the object resulting from the parse.
  * @throws ParseException
  *            if an error occurs during parsing.
  */
 public Object parseObject(String s)
 {
     //throws ParseException {
     ParsePosition position = new ParsePosition(0);
     Object result = parseObject(s, position);
     if (position.getIndex() == 0) {
         // text.1C=Format.parseObject(String) parse failure
         throw new ParseException("Format.parseObject(String) parse failure", position.getErrorIndex()); //$NON-NLS-1$
     }
     return result;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Parse String with given pattern on ParsePosition to Data object
        /// </summary>
        /// <param name="s"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public java.util.Date parse(String s, ParsePosition pos)
        {
            DateTime date = DateTime.ParseExact(s.substring(pos.getIndex()), pattern, CultureInfo.InvariantCulture);

            return(new java.util.Date(date.getTime()));
        }