예제 #1
0
  /**
   * Analyze a picture string into two sub-pictures.
   *
   * @param picture the picture as written (possibly two subpictures separated by a semicolon)
   * @param dfs the decimal format symbols
   * @return an array of two sub-pictures, the positive and the negative sub-pictures respectively.
   *     If there is only one sub-picture, the second one is null.
   */
  private SubPicture[] getSubPictures(String picture, DecimalSymbols dfs) throws XPathException {
    int[] picture4 = StringValue.expand(picture);
    SubPicture[] pics = new SubPicture[2];
    if (picture4.length == 0) {
      XPathException err = new XPathException("format-number() picture is zero-length");
      err.setErrorCode("XTDE1310");
      throw err;
    }
    int sep = -1;
    for (int c = 0; c < picture4.length; c++) {
      if (picture4[c] == dfs.patternSeparator) {
        if (c == 0) {
          grumble("first subpicture is zero-length");
        } else if (sep >= 0) {
          grumble("more than one pattern separator");
        } else if (sep == picture4.length - 1) {
          grumble("second subpicture is zero-length");
        }
        sep = c;
      }
    }

    if (sep < 0) {
      pics[0] = new SubPicture(picture4, dfs);
      pics[1] = null;
    } else {
      int[] pic0 = new int[sep];
      System.arraycopy(picture4, 0, pic0, 0, sep);
      int[] pic1 = new int[picture4.length - sep - 1];
      System.arraycopy(picture4, sep + 1, pic1, 0, picture4.length - sep - 1);
      pics[0] = new SubPicture(pic0, dfs);
      pics[1] = new SubPicture(pic1, dfs);
    }
    return pics;
  }
예제 #2
0
 /**
  * Insert an integer into an array of integers. This may or may not modify the supplied array.
  *
  * @param array the initial array
  * @param used the number of items in the initial array that are used
  * @param value the integer to be inserted
  * @param position the position of the new integer in the final array
  * @return the new array, with the new integer inserted
  */
 private static int[] insert(int[] array, int used, int value, int position) {
   if (used + 1 > array.length) {
     int[] a2 = new int[used + 10];
     System.arraycopy(array, 0, a2, 0, used);
     array = a2;
   }
   for (int i = used - 1; i >= position; i--) {
     array[i + 1] = array[i];
   }
   array[position] = value;
   return array;
 }