Esempio n. 1
1
  static ByteStream pack(String format, FormatDef[] f, int size, int start, PyObject[] args) {
    ByteStream res = new ByteStream();

    int i = start;
    int len = format.length();
    for (int j = 0; j < len; j++) {
      char c = format.charAt(j);
      if (j == 0 && (c == '@' || c == '<' || c == '>' || c == '=' || c == '!')) continue;
      if (Character.isWhitespace(c)) continue;
      int num = 1;
      if (Character.isDigit(c)) {
        num = Character.digit(c, 10);
        while (++j < len && Character.isDigit((c = format.charAt(j))))
          num = num * 10 + Character.digit(c, 10);
        if (j >= len) break;
      }

      FormatDef e = getentry(c, f);

      // Fill pad bytes with zeros
      int nres = align(res.size(), e) - res.size();
      while (nres-- > 0) res.writeByte(0);
      i += e.doPack(res, num, i, args);
    }

    if (i < args.length) throw StructError("too many arguments for pack format");

    return res;
  }
Esempio n. 2
0
    /** Check if we are still in the number */
    public boolean isWordPart(char c) {
      // ok, we have to test for scientific notation e.g.: 10.9e10

      if ((c == 'x' || c == 'X') && buffer.length() == 1 && buffer.charAt(0) == '0') {
        // it is an hexadecimal
        buffer.append(c);
        isInHexa = true;
        return true;
      } else {
        buffer.append(c);
      }

      if (isInHexa) {
        return Character.isDigit(c)
            || c == 'a'
            || c == 'A'
            || c == 'b'
            || c == 'B'
            || c == 'c'
            || c == 'C'
            || c == 'd'
            || c == 'D'
            || c == 'e'
            || c == 'E'
            || c == 'f'
            || c == 'F';

      } else {
        return Character.isDigit(c) || c == 'e' || c == '.';
      }
    }
  /**
   * Creates the {@link AbstractAddress} from a {@link Spreadsheet} specified by a String in A1
   * Notion.
   *
   * @param a1Notion
   * @return
   */
  private static AbstractAddress createCellAddress(String a1Notion) {
    CellAddress address = null;

    if (Character.isLetter(a1Notion.charAt(0))
        && Character.isDigit(a1Notion.charAt(a1Notion.length() - 1))) {
      Integer horizontalIndex = 0;
      Integer verticalIndex = 0;

      // First convert the letters to the column index
      int i = 0;
      char currentChar = a1Notion.charAt(i);

      while (i < a1Notion.length() && Character.isLetter(currentChar)) {
        horizontalIndex += characterToColumnIndex(currentChar);
        i++;
        currentChar = a1Notion.charAt(i);
      }

      // Then convert the number part to the row index
      if (Character.isDigit(currentChar)) {
        verticalIndex = Integer.parseInt(a1Notion.substring(i));
      }

      address = new CellAddress();
      address.setColumnIndex(horizontalIndex);
      address.setRowIndex(verticalIndex);
    }

    return address;
  }
Esempio n. 4
0
  void stringSetup(String str) {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < str.length(); i++) {
      char ch = str.charAt(i);
      if (ch == '\\') {
        // get next character
        ch = str.charAt(++i);

        if (Character.isDigit(ch)) {
          int endPos = i;

          // check the next two characters
          while (endPos < i + 2) {
            if (Character.isDigit(str.charAt(endPos + 1))) endPos++;
            else break;
          }

          ch = (char) Integer.parseInt(str.substring(i, endPos + 1), 8);
          i = endPos;
        } else ch = getEscapeChar(ch);
      }

      buffer.append(ch);
    }

    value = buffer.toString().intern();
  }
 public int calculate(String s) {
   Stack<Integer> stack = new Stack<Integer>();
   int num = 0;
   char sign = '+';
   for (int i = 0; i < s.length(); i++) {
     char c = s.charAt(i);
     if (Character.isDigit(c)) {
       num = num * 10 + (c - '0');
     }
     if (i == s.length() - 1 || !Character.isDigit(c) && c != ' ') {
       switch (sign) {
         case '+':
           stack.push(+num);
           break;
         case '-':
           stack.push(-num);
           break;
         case '*':
           stack.push(stack.pop() * num);
           break;
         case '/':
           stack.push(stack.pop() / num);
           break;
       }
       sign = c;
       num = 0;
     }
   }
   int result = 0;
   while (!stack.isEmpty()) result += stack.pop();
   return result;
 }
 private void tf_valorKeyTyped(java.awt.event.KeyEvent evt) { // GEN-FIRST:event_tf_valorKeyTyped
   // TODO add your handling code here:
   if (list_filtros.getSelectedItem() == "Nombre") {
     ch = evt.getKeyChar();
     if (Character.isDigit(ch)) {
       getToolkit().beep();
       evt.consume();
     }
   }
   if (list_filtros.getSelectedItem() == "Empleado") {
     ch = evt.getKeyChar();
     if (Character.isDigit(ch)) {
       getToolkit().beep();
       evt.consume();
     } else {
       if (list_filtros.getSelectedItem() == "Código") {
         ch = evt.getKeyChar();
         if (!Character.isDigit(ch)) {
           getToolkit().beep();
           evt.consume();
         }
       }
     }
   }
 } // GEN-LAST:event_tf_valorKeyTyped
Esempio n. 7
0
 public boolean isPalindrome(String s) {
   if (s.length() == 0) return true;
   // System.out.println(cs);
   int i = 0, j = s.length() - 1;
   boolean flag = true;
   while (i < j) {
     // System.out.println(s.charAt(i)+" vs " + s.charAt(j)  );
     if (Character.isLetterOrDigit(s.charAt(i)) == false) {
       // System.out.println("i is not alphanumeric " + s.charAt(i)  );
       i++;
       continue;
     }
     if (Character.isLetterOrDigit(s.charAt(j)) == false) {
       // System.out.println("j is not alphanumeric:" + s.charAt(j)  );
       j--;
       continue;
     }
     if (s.charAt(i) == s.charAt(j) || Math.abs(s.charAt(i) - s.charAt(j)) == 32) {
       if ((Character.isDigit(s.charAt(i)) && Character.isLetter(s.charAt(j)))
           || (Character.isDigit(s.charAt(j)) && Character.isLetter(s.charAt(i)))) {
         flag = false;
         break;
       }
       flag = true;
       i++;
       j--;
     } else {
       flag = false;
       // System.out.println(s.charAt(i)+" vs " + s.charAt(j)  );
       break;
     }
   }
   System.out.println(flag);
   return flag;
 }
Esempio n. 8
0
  public int calculate(String s) {
    Stack<Integer> stack = new Stack<>();
    int size = s.length();
    if (s == null || size == 0) return 0;

    char sign = '+';
    for (int i = 0; i < size; i++) {
      char c = s.charAt(i);
      int cur = 0;
      if (Character.isDigit(c)) {
        cur = c - '0';
        while (i + 1 < size && Character.isDigit(s.charAt(i + 1))) {
          cur = cur * 10 + (s.charAt(++i) - '0');
        }
      }
      if (c != ' ' || i == size - 1) {
        if (sign == '+') {
          stack.push(cur);
        } else if (sign == '-') {
          stack.push(-cur);
        } else if (sign == '*') {
          stack.push(stack.pop() * cur);
        } else if (sign == '/') {
          stack.push(stack.pop() / cur);
        }
        cur = 0;
        sign = s.charAt(i);
      }
    }
    int res = 0;
    for (int i : stack) res = res + i;
    return res;
  }
Esempio n. 9
0
  // Returns the first non-digit (and not a '.') character in a file under the
  //    assumption that it is the delimiter in the file.
  private static char determineDelimiter(String filePath) {
    final char DEFAULT_DELIMITER = ',';

    try {
      final BufferedReader in = new BufferedReader(new FileReader(filePath));

      String line = in.readLine().trim(); // read first line

      if (!Character.isDigit(line.charAt(0))) // go to 2nd line if 1st line appears to be labels
      line = in.readLine();

      in.close();

      // Searches the 2nd line of the file until a non-number character is
      //    found.  The delimiter is assumed to be that character.
      //    numbers, minus signs, periods, and 'E' (exponent) are accepted
      //    number characters.
      for (int x = 0; x < line.length(); x++) {
        if (!Character.isDigit(line.charAt(x))
            && (line.charAt(x) != '.')
            && (line.charAt(x) != '-')
            && (Character.toUpperCase(line.charAt(x)) != 'E')) return line.charAt(x);
      }

      // No delimiters were found, which means that there must be only one column
      //    A delimiter does not need to be known to read this file.
      return DEFAULT_DELIMITER;
    } catch (IOException e) {
      return DEFAULT_DELIMITER;
    }
  } // end determineDelimiter(.)
Esempio n. 10
0
 public static boolean isFormat(String str, String... format) {
   if (str.length() == 0) return format.length == 1 && format[0].equals("");
   char[] charset = str.toCharArray();
   int c = 0;
   for (int i = 0; i < format.length; i++) {
     String form = format[i];
     if (form.equals(NUMBERS)) {
       if (c >= charset.length) return false;
       if (!Character.isDigit(charset[c])) {
         if (charset[c] == '.') {
           if (c + 1 >= charset.length || !Character.isDigit(charset[c + 1])) return false;
         } else return false;
       }
       while (c < charset.length - 1
           && (Character.isDigit(charset[c + 1]) || charset[c + 1] == '.')) c++;
       c++;
     } else if (form.equals(LETTERS)) {
       if (c >= charset.length || !Character.isLetter(charset[c])) return false;
       while (c < charset.length - 1 && Character.isLetter(charset[c + 1])) c++;
       c++;
     } else {
       char[] formchars = form.toCharArray();
       if (formchars.length > charset.length - c) return false;
       for (int ch = 0; ch < formchars.length; ch++) {
         if (formchars[ch] != charset[c]) return false;
         c++;
       }
     }
   }
   return c == charset.length;
 }
  private List<ExpressionAtom> parseInputPolynomial(String inputExpression) {
    inputExpression = identifyUnaryMinuses(inputExpression);
    inputExpression = insertMultiplicationSigns(inputExpression);

    List<ExpressionAtom> inputExpressionTokens = new ArrayList<ExpressionAtom>();

    char[] inputChars = inputExpression.toCharArray();
    for (int i = 0; i < inputChars.length; ++i) {
      if (isOperator(inputChars[i]) || inputChars[i] == '%') {
        inputExpressionTokens.add(
            new ExpressionAtom(String.valueOf(inputChars[i]), AtomType.OPERATOR, 1));
      } else {
        int lastIndex = inputExpressionTokens.size() - 1;
        if (lastIndex >= 0
            && inputExpressionTokens.get(lastIndex).getAtomType() == AtomType.OPERAND) {
          ExpressionAtom lastElement = inputExpressionTokens.remove(lastIndex);
          if (Character.isDigit(inputChars[i])) {
            lastElement.setCoefficient(
                lastElement.getCoefficient() * 10 + Character.getNumericValue(inputChars[i]));
          } else {
            lastElement.setVariablesOrOperator(
                lastElement.getVariablesOrOperator() + String.valueOf(inputChars[i]));
          }
          inputExpressionTokens.add(lastElement);
        } else if (Character.isDigit(inputChars[i])) {
          inputExpressionTokens.add(
              new ExpressionAtom("", AtomType.OPERAND, Character.getNumericValue(inputChars[i])));
        } else {
          inputExpressionTokens.add(
              new ExpressionAtom(String.valueOf(inputChars[i]), AtomType.OPERAND, 1));
        }
      }
    }
    return inputExpressionTokens;
  }
 private static boolean needsDelimiting(String rawSheetName) {
   int len = rawSheetName.length();
   if (len < 1) {
     throw new RuntimeException("Zero length string is an invalid sheet name");
   }
   if (Character.isDigit(rawSheetName.charAt(0))) {
     // sheet name with digit in the first position always requires delimiting
     return true;
   }
   for (int i = 0; i < len; i++) {
     char ch = rawSheetName.charAt(i);
     if (isSpecialChar(ch)) {
       return true;
     }
   }
   if (Character.isLetter(rawSheetName.charAt(0))
       && Character.isDigit(rawSheetName.charAt(len - 1))) {
     final int j = rawSheetName.indexOf(':');
     if (j >= 0) {
       if (nameLooksLikePlainCellReference(rawSheetName.substring(0, j))
           || nameLooksLikePlainCellReference(rawSheetName.substring(j + 1))) {
         return true;
       }
     } else if (nameLooksLikePlainCellReference(rawSheetName)) {
       return true;
     }
   }
   if (nameLooksLikeBooleanLiteral(rawSheetName)) {
     return true;
   }
   // Error constant literals all contain '#' and other special characters
   // so they don't get this far
   return false;
 }
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    while (--n >= 0) {
      String coord = scan.next();

      int cIndex = coord.indexOf('C');
      if (coord.startsWith("R") && Character.isDigit(coord.charAt(1)) && cIndex != -1) {
        int row = Integer.parseInt(coord.substring(1, cIndex));
        int col = Integer.parseInt(coord.substring(cIndex + 1));

        StringBuilder colStr = new StringBuilder();
        while (col > 0) {
          colStr.insert(0, (char) ((col - 1) % 26 + 'A'));
          col = (col - 1) / 26;
        }
        System.out.println(colStr.toString() + row);
      } else {
        int split = 1;
        while (!Character.isDigit(coord.charAt(split))) split++;

        String colStr = coord.substring(0, split);
        int row = Integer.parseInt(coord.substring(split));

        int col = 0;
        for (int i = 0; i < colStr.length(); i++) {
          col *= 26;
          col += colStr.charAt(i) - 'A' + 1;
        }
        System.out.println("R" + row + "C" + col);
      }
    }
  }
Esempio n. 14
0
  static int calcsize(String format, FormatDef[] f) {
    int size = 0;

    int len = format.length();
    for (int j = 0; j < len; j++) {
      char c = format.charAt(j);
      if (j == 0 && (c == '@' || c == '<' || c == '>' || c == '=' || c == '!')) continue;
      if (Character.isWhitespace(c)) continue;
      int num = 1;
      if (Character.isDigit(c)) {
        num = Character.digit(c, 10);
        while (++j < len && Character.isDigit((c = format.charAt(j)))) {
          int x = num * 10 + Character.digit(c, 10);
          if (x / 10 != num) throw StructError("overflow in item count");
          num = x;
        }
        if (j >= len) break;
      }

      FormatDef e = getentry(c, f);

      int itemsize = e.size;
      size = align(size, e);
      int x = num * itemsize;
      size += x;
      if (x / itemsize != num || size < 0) throw StructError("total struct size too long");
    }
    return size;
  }
  private Comparable[] makeGroups(String s) {
    List<Comparable> l = new ArrayList<Comparable>();
    boolean isNumber = false;
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      if (sb.length() > 0) {
        char last = sb.charAt(sb.length() - 1);
        if ((Character.isDigit(c) && Character.isDigit(last))
            || (!Character.isDigit(c) && !Character.isDigit(last))) {
        } else {
          if (isNumber) {
            l.add(new BigInteger(sb.toString()));
          } else {
            l.add(sb.toString());
          }
          sb.setLength(0);
        }
      }
      sb.append(c);
      isNumber = Character.isDigit(c);
    }
    if (sb.length() > 0) {
      if (isNumber) {
        l.add(new BigInteger(sb.toString()));
      } else {
        l.add(sb.toString());
      }
    }
    Comparable[] cs = new Comparable[l.size()];
    return l.toArray(cs);
  }
Esempio n. 16
0
 static {
   String javaVersion = System.getProperty("java.version");
   // Value is on the form M.N.U_P[-xxx] where M,N,U,P are decimal integers
   if (null != javaVersion) {
     int startPos = 0;
     int endPos = 0;
     int max = javaVersion.length();
     while (endPos < max && Character.isDigit(javaVersion.charAt(endPos))) {
       endPos++;
     }
     if (startPos < endPos) {
       try {
         javaVersionMajor = Integer.parseInt(javaVersion.substring(startPos, endPos));
         startPos = endPos + 1;
         endPos = startPos;
         while (endPos < max && Character.isDigit(javaVersion.charAt(endPos))) {
           endPos++;
         }
         if (startPos < endPos) {
           javaVersionMinor = Integer.parseInt(javaVersion.substring(startPos, endPos));
           startPos = endPos + 1;
           endPos = startPos;
           while (endPos < max && Character.isDigit(javaVersion.charAt(endPos))) {
             endPos++;
           }
           if (startPos < endPos) {
             javaVersionMicro = Integer.parseInt(javaVersion.substring(startPos, endPos));
           }
         }
       } catch (NumberFormatException _nfe) {
       }
     }
   }
 }
Esempio n. 17
0
  public static int calculate(String s) { // 使用栈来计算表达式的值
    if (s == null || s.length() == 0) return 0;

    Stack<Integer> stack = new Stack<Integer>(); // 只有在遇到 () 时才会用到栈
    int ans = 0; // 用来存放当前计算的结果
    int sign = 1; // 用来存放下一个运算的符号

    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i); // 拿出字符
      if (Character.isDigit(c)) { // 如果是数字
        int cur = c - '0';
        while (i + 1 < s.length() && Character.isDigit(s.charAt(i + 1))) {
          cur = 10 * cur + s.charAt(++i) - '0';
        } // 把数字拼凑完成
        ans += sign * cur; // 计算下结果
      } else if (c == '-') {
        sign = -1; // 下一次做-
      } else if (c == '+') {
        sign = 1; // 下一次做+
      } else if (c == '(') { // 如果是(
        stack.push(ans); // 则把 结果 和 运算符号一起入栈,ans sign重置
        ans = 0; // 必须,不然括号里第一个数字立即运算了
        stack.push(sign);
        sign = 1; // 必须,不然括号里第一个数字之前的符号不确定
      } else if (c == ')') { // 如果是)
        ans = stack.pop() * ans + stack.pop(); // 则把 运算符 和 结果一起出栈, 计算当前的结果
      }
    }
    return ans;
  }
Esempio n. 18
0
 public static VideoFormat buildVideoFormatForResolution(String s) {
   if (s == null || s.length() == 0) return null;
   VideoFormat rv = new VideoFormat();
   rv.setFormatName(s);
   try {
     int xidx = s.indexOf('x');
     if (xidx == -1) return rv;
     rv.width = Integer.parseInt(s.substring(0, xidx));
     int lastIdx = xidx + 1;
     while (Character.isDigit(s.charAt(lastIdx))) {
       lastIdx++;
       if (lastIdx >= s.length()) break;
     }
     rv.height = Integer.parseInt(s.substring(xidx + 1, lastIdx));
     if (lastIdx < s.length() && s.charAt(lastIdx) == 'i') rv.interlaced = true;
     int atSym = s.indexOf('@');
     if (atSym != -1) {
       lastIdx = atSym + 1;
       while (Character.isDigit(s.charAt(lastIdx)) || s.charAt(lastIdx) == '.') {
         lastIdx++;
         if (lastIdx >= s.length()) break;
       }
       rv.fps = Float.parseFloat(s.substring(atSym + 1, lastIdx));
     }
     return rv;
   } catch (Exception e) {
     System.out.println("Error parsing resolution:" + s + " of:" + e);
     return rv;
   }
 }
Esempio n. 19
0
 public Date parse(String source, ParsePosition pos) {
   calendar.clear();
   int p = 0;
   try {
     String s = parseTZ(source);
     int l = s.length();
     calendar.set(Calendar.YEAR, Integer.parseInt(s.substring(p, p + 4)));
     p += 4;
     if (l > p) {
       if (!Character.isDigit(s.charAt(p))) {
         ++p;
       }
       calendar.set(Calendar.MONTH, Integer.parseInt(s.substring(p, p + 2)) - 1);
       p += 2;
       if (l > p) {
         if (!Character.isDigit(s.charAt(p))) {
           ++p;
         }
         calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(s.substring(p, p + 2)));
         p += 2;
         if (l > p) {
           if (!Character.isDigit(s.charAt(p))) {
             ++p;
           }
           calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(s.substring(p, p + 2)));
           p += 2;
           if (l > p) {
             if (s.charAt(p) == ':') {
               ++p;
             }
             calendar.set(Calendar.MINUTE, Integer.parseInt(s.substring(p, p + 2)));
             p += 2;
             if (l > p) {
               if (s.charAt(p) == ':') {
                 ++p;
               }
               calendar.set(Calendar.SECOND, Integer.parseInt(s.substring(p)));
             } else {
               clearCalendarFields(Calendar.SECOND);
             }
           } else {
             clearCalendarFields(Calendar.MINUTE);
           }
         } else {
           clearCalendarFields(Calendar.HOUR_OF_DAY);
         }
       } else {
         clearCalendarFields(Calendar.DAY_OF_MONTH);
       }
     } else {
       clearCalendarFields(Calendar.MONTH);
     }
     pos.setIndex(source.length());
     return calendar.getTime();
   } catch (Exception e) {
     pos.setErrorIndex(p);
     return null;
   }
 }
Esempio n. 20
0
 private static String parseNakedString(String string) {
   // return StringUtils.javaUnEscape(string)
   int len = string.length();
   StringBuffer b = new StringBuffer(len);
   for (int i = 0; i < len; ) {
     char c = string.charAt(i++);
     if (c == '\\') {
       c = string.charAt(i++);
       switch (c) {
         case 't':
           b.append('\t');
           break;
         case 'n':
           b.append('\n');
           break;
         case 'r':
           b.append('\r');
           break;
         case 'f':
           b.append('\f');
           break;
         case 'b':
           b.append('\b');
           break;
         case '\\':
           b.append('\\');
           break;
         case '"':
           b.append('"');
           break;
         case '\'':
           b.append('\'');
           break;
         case 'u':
           if (i < (len - 3)) {
             b.append((char) Integer.parseInt(string.substring(i, i + 4), 16));
             i += 4;
           }
           break;
         case '0':
           b.append('\0');
           break;
         default:
           if (Character.isDigit(c)) {
             int start = i - 1;
             int end = i;
             while (Character.isDigit(string.charAt(end))) {
               end++;
             }
             b.append((char) Integer.parseInt(string.substring(start, end), 8));
             i = end;
           }
       }
     } else {
       b.append(c);
     }
   }
   return b.toString();
 }
Esempio n. 21
0
  /**
   * Parses a version for major/minor/service & revision. Only Major is required. If Minor, Service
   * or Revision don't exist, they are assumed to be 0.
   */
  private int[] parse(String vers) throws VersionFormatException {
    int major, minor, service, revision;
    int dot1, dot2, lastNum;

    dot1 = vers.indexOf(".");
    if (dot1 != -1) {
      dot2 = vers.indexOf(".", dot1 + 1);
      if (dot2 == -1) dot2 = vers.length();
    } else {
      dot1 = vers.length();
      dot2 = -1;
    }

    try {
      major = Integer.parseInt(vers.substring(0, dot1));
    } catch (NumberFormatException nfe) {
      throw new VersionFormatException(vers);
    }

    minor = 0;
    service = 0;
    revision = 0;

    if (dot2 != -1) {
      try {
        minor = Integer.parseInt(vers.substring(dot1 + 1, dot2));
      } catch (NumberFormatException nfe) {
        throw new VersionFormatException(vers);
      }

      try {
        int q = dot2 + 1;
        // advance to the first digit
        while (q < vers.length() && Character.isDigit(vers.charAt(q))) q++;

        lastNum = q;
        if (q <= vers.length()) service = Integer.parseInt(vers.substring(dot2 + 1, q));
      } catch (NumberFormatException nfe) {
        throw new VersionFormatException(vers);
      }

      try {
        int q = lastNum + 1;
        // advance to the first digit
        while (q < vers.length() && !Character.isDigit(vers.charAt(q))) q++;
        int p = q;
        // advance to the first non-digit
        while (p < vers.length() && Character.isDigit(vers.charAt(p))) p++;

        if (q < vers.length() && p <= vers.length())
          revision = Integer.parseInt(vers.substring(q, p));
      } catch (NumberFormatException okay) {
        // not everything will have a revision digit.
      }
    }

    return new int[] {major, minor, service, revision};
  }
Esempio n. 22
0
  public static float correctTotRaisedMoney(String totalMoney) {
    char[] totalmoneychar = totalMoney.toCharArray();
    int firstDigitChar = 0;
    boolean isdollar;
    char currCode = ' ';
    // if it only contains digits
    if (totalMoney.matches("^[0-9]+\\.?[0-9]*$")) {
      return Float.parseFloat(totalMoney);
    }

    if (totalMoney.length() < 3) {
      System.out.println("Total raised money " + "0");
      return 0.0f;
    }

    isdollar = (totalmoneychar[0] == '$') ? true : false;
    if (!Character.isDigit(totalmoneychar[totalmoneychar.length - 1]))
      currCode = totalmoneychar[totalmoneychar.length - 1];

    while (!Character.isDigit(totalmoneychar[firstDigitChar])) {
      firstDigitChar++;
    }

    //
    ArrayList<Character> totalMoneylist = new ArrayList<Character>();
    for (int i = firstDigitChar; i < totalmoneychar.length - 1; i++) {
      char temp = totalmoneychar[i];
      if (Character.isDigit(temp)) totalMoneylist.add(temp);
      else if (temp == '.') totalMoneylist.add(temp);
      else totalMoneylist.add('0');
    }

    String totalmoneystring = "";
    //
    for (int i = 0; i < totalMoneylist.size(); i++) {
      totalmoneystring += totalMoneylist.get(i);
    }

    float totalraisedmoney = 0.0f;
    if (currCode == 'k' || currCode == 'K') {
      totalraisedmoney = Float.parseFloat(totalmoneystring);
      totalraisedmoney *= 1000; // 10 raise to 3
    } else if (currCode == 'm' || currCode == 'M') {

      totalraisedmoney = Float.parseFloat(totalmoneystring);
      totalraisedmoney *= 1000000; // 10 raise to 6
    } else if (currCode == 'b' || currCode == 'B') {
      totalraisedmoney = Float.parseFloat(totalmoneystring);
      totalraisedmoney *= 1000000000; // 10 raise to 9
    } else {
      totalraisedmoney = Float.parseFloat(totalmoneystring);
    }

    System.out.println("total raised money -> " + totalraisedmoney);

    return totalraisedmoney;
  }
Esempio n. 23
0
 int number() {
   if (!Character.isDigit(cs[p])) return 1;
   int res = 0;
   while (Character.isDigit(cs[p])) {
     res *= 10;
     res += cs[p++] - '0';
   }
   return res;
 }
Esempio n. 24
0
 public static boolean call_isCorrect_1221565233201(SNode thisNode) {
   boolean isEscapeMode = false;
   boolean isUnicodeMode = false;
   boolean isSymbolCodeMode = false;
   int digitNumber = 0;
   int unicodeDigitNumber = 0;
   String value = SPropertyOperations.getString(thisNode, "value");
   if (value == null) {
     return true;
   }
   for (int i = 0; i < value.length(); i++) {
     char c = SPropertyOperations.getString(thisNode, "value").charAt(i);
     if (isEscapeMode) {
       if (c == 'u') {
         isUnicodeMode = true;
       } else if (Character.isDigit(c)) {
         isSymbolCodeMode = true;
         digitNumber = 1;
       } else if (c != 'n' && c != 't' && c != 'b' && c != 'f' && c != 'r' && c != '"' && c != '\''
           && c != '\\') {
         return false;
       }
       isEscapeMode = false;
     } else if (c == '\\') {
       isEscapeMode = true;
     } else if (isSymbolCodeMode) {
       if (Character.isDigit(c)) {
         digitNumber++;
       } else {
         return false;
       }
       if (digitNumber == 3) {
         isSymbolCodeMode = false;
         digitNumber = 0;
       }
     } else if (isUnicodeMode) {
       if (Character.isDigit(c)
           || StringLiteral_Behavior.call_isHexChar_1221565869792(thisNode, c)) {
         unicodeDigitNumber++;
       } else {
         return false;
       }
       if (unicodeDigitNumber == 4) {
         isUnicodeMode = false;
         unicodeDigitNumber = 0;
       }
     } else if (c == '"') {
       return false;
     }
   }
   if (isEscapeMode || isUnicodeMode) {
     return false;
   }
   return true;
 }
Esempio n. 25
0
 public static BitSet unescapeBitset(String str) {
   char ch;
   int len;
   if (str == null
       || (len = (str = str.trim()).length()) < 4
       || str.equalsIgnoreCase("({null})")
       || (ch = str.charAt(0)) != '(' && ch != '['
       || str.charAt(len - 1) != (ch == '(' ? ')' : ']')
       || str.charAt(1) != '{'
       || str.indexOf('}') != len - 2) return null;
   len -= 2;
   for (int i = len; --i >= 2; )
     if (!Character.isDigit(ch = str.charAt(i)) && ch != ' ' && ch != '\t' && ch != ':')
       return null;
   int lastN = len;
   while (Character.isDigit(str.charAt(--lastN))) {
     // loop
   }
   if (++lastN == len) lastN = 0;
   else
     try {
       lastN = Integer.parseInt(str.substring(lastN, len));
     } catch (NumberFormatException e) {
       return null;
     }
   BitSet bs = new BitSet(lastN);
   lastN = -1;
   int iPrev = -1;
   int iThis = -2;
   for (int i = 2; i <= len; i++) {
     switch (ch = str.charAt(i)) {
       case '\t':
       case ' ':
       case '}':
         if (iThis < 0) break;
         if (iThis < lastN) return null;
         lastN = iThis;
         if (iPrev < 0) iPrev = iThis;
         bs.set(iPrev, iThis + 1);
         iPrev = -1;
         iThis = -2;
         break;
       case ':':
         iPrev = lastN = iThis;
         iThis = -2;
         break;
       default:
         if (Character.isDigit(ch)) {
           if (iThis < 0) iThis = 0;
           iThis = (iThis << 3) + (iThis << 1) + (ch - '0');
         }
     }
   }
   return (iPrev >= 0 ? null : bs);
 }
Esempio n. 26
0
 private static String unescape(String s) {
   StringBuffer sbuf = new StringBuffer();
   int l = s.length();
   int ch = -1;
   int b, sumb = 0;
   for (int i = 0, more = -1; i < l; i++) {
     /* Get next byte b from URL segment s */
     switch (ch = s.charAt(i)) {
       case '%':
         ch = s.charAt(++i);
         int hb =
             (Character.isDigit((char) ch)
                     ? ch - '0'
                     : 10 + Character.toLowerCase((char) ch) - 'a')
                 & 0xF;
         ch = s.charAt(++i);
         int lb =
             (Character.isDigit((char) ch)
                     ? ch - '0'
                     : 10 + Character.toLowerCase((char) ch) - 'a')
                 & 0xF;
         b = (hb << 4) | lb;
         break;
       case '+':
         b = ' ';
         break;
       default:
         b = ch;
     }
     /* Decode byte b as UTF-8, sumb collects incomplete chars */
     if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
       sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb
       if (--more == 0) sbuf.append((char) sumb); // Add char to sbuf
     } else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits)
       sbuf.append((char) b); // Store in sbuf
     } else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits)
       sumb = b & 0x1f;
       more = 1; // Expect 1 more byte
     } else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits)
       sumb = b & 0x0f;
       more = 2; // Expect 2 more bytes
     } else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits)
       sumb = b & 0x07;
       more = 3; // Expect 3 more bytes
     } else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits)
       sumb = b & 0x03;
       more = 4; // Expect 4 more bytes
     } else /*if ((b & 0xfe) == 0xfc)*/ { // 1111110x (yields 1 bit)
       sumb = b & 0x01;
       more = 5; // Expect 5 more bytes
     }
     /* We don't test if the UTF-8 encoding is well-formed */
   }
   return sbuf.toString();
 }
Esempio n. 27
0
  /** Разбор аргументов */
  @Override
  public int parseArguments(Parameters params) throws CmdLineException {
    String token = params.getParameter(0);
    int usedParams = 1;

    OptionSize size = new OptionSize();

    // отцепляем цифры
    int i = 0;
    for (; i < token.length(); ++i) if (!Character.isDigit(token.charAt(i))) break;

    // нету чисел
    if (i - 1 < 1) throw new CmdLineException(owner, "Illegal argument in -size option.");

    // парсим первое число
    size.width = Integer.parseInt(token.substring(0, i));

    // просканили весь параметр
    if (i == token.length()) {
      if (params.size() < 2)
        throw new CmdLineException(owner, "Wrong number arguments in -size option.");
      token = params.getParameter(1);
      usedParams++;
      i = 0;
    }

    if (token.charAt(i) != 'x')
      throw new CmdLineException(owner, "Illegal argument in -size option.");

    i++;

    // просканили весь параметр
    if (i == token.length()) {
      if (params.size() < usedParams + 1)
        throw new CmdLineException(owner, "Wrong number arguments in -size option.");
      token = params.getParameter(usedParams);
      usedParams++;
      i = 0;
    }

    // отцепляем цифры второго числа
    int j = i;
    for (; i < token.length(); ++i) if (!Character.isDigit(token.charAt(i))) break;

    // за цифрами что-то есть
    if (i != token.length()) throw new CmdLineException(owner, "Illegal argument in -size option.");

    size.height = Integer.parseInt(token.substring(j, i));

    setter.addValue(size);

    return usedParams;
  }
 public static int add(String line) {
   if (line.isEmpty()) return 0;
   String number = "";
   int i = 0;
   int startIndex = 0;
   int endIndex = 0;
   for (i = 0; i < line.length(); i++) if (Character.isDigit(line.charAt(i))) startIndex = i;
   for (; i < line.length() && Character.isDigit(line.charAt(i)); i++) ;
   endIndex = i;
   number = line.substring(--startIndex, endIndex);
   return Integer.parseInt(number) + add(line.substring(endIndex));
 }
Esempio n. 29
0
 /**
  * Modtager værtens svar, der godt kan løbe over flere linjer. Sidste linje er en svarkode på tre
  * cifre, uden en bindestreg '-' på plads nummer 4
  */
 private String læsSvar() throws IOException {
   while (true) {
     String s = ind.readLine();
     System.out.println("modt: " + s);
     if (s.length() >= 3
         && s.charAt(3) != '-'
         && Character.isDigit(s.charAt(0))
         && Character.isDigit(s.charAt(1))
         && Character.isDigit(s.charAt(2)))
       return s; // afslut løkken og returner sidste linje med statuskode
   }
 }
Esempio n. 30
0
 private static String reformatTimezone(String str, int signIdx) {
   String str2 = str;
   if ((signIdx >= 0)
       && (signIdx + 5 < str.length())
       && (Character.isDigit(str.charAt(signIdx + 1)))
       && (Character.isDigit(str.charAt(signIdx + 2)))
       && (str.charAt(signIdx + 3) == ':')
       && (Character.isDigit(str.charAt(signIdx + 4)))
       && (Character.isDigit(str.charAt(signIdx + 5)))) {
     str2 = str.substring(0, signIdx + 3) + str.substring(signIdx + 4);
   }
   return str2;
 }