// reconstruct the unused tokens from the phrase (since it didn't match)
  // need to recompute the token positions based on the length of the currentPhrase,
  // the current ending position and the length of each token.
  private void discardCharTokens(StringBuffer phrase, ArrayList<Token> tokenList) {
    Log.debug("discardCharTokens: '" + phrase.toString() + "'");
    OffsetAttribute offAttr = getOffsetAttribute();
    int endPos = offAttr.endOffset();
    int startPos = endPos - phrase.length();

    int lastSp = 0;
    for (int i = 0; i < phrase.length(); i++) {
      char chAt = phrase.charAt(i);
      if (isSpaceChar(chAt) && i > lastSp) {
        char[] tok = new char[i - lastSp];
        phrase.getChars(lastSp, i, tok, 0);
        if (lastEmitted == null || !endsWith(lastEmitted, tok)) {
          Token token = new Token();
          token.tok = tok;

          token.startPos = startPos + lastSp;
          token.endPos = token.startPos + tok.length;
          Log.debug("discard " + new String(tok) + ": " + token.startPos + ", " + token.endPos);
          tokenList.add(token);
        }
        lastSp = i + 1;
      }
    }
    char[] tok = new char[phrase.length() - lastSp];
    phrase.getChars(lastSp, phrase.length(), tok, 0);

    Token token = new Token();
    token.tok = tok;
    token.endPos = endPos;
    token.startPos = endPos - tok.length;
    tokenList.add(token);
  }
예제 #2
0
 public char[] getContents() {
   char[] result = null;
   FileInputStream is = null;
   try {
     is = new FileInputStream(sourceFile);
     Reader reader =
         new BufferedReader(new InputStreamReader(is, ctxt.getOptions().getJavaEncoding()));
     if (reader != null) {
       char[] chars = new char[8192];
       StringBuffer buf = new StringBuffer();
       int count;
       while ((count = reader.read(chars, 0, chars.length)) > 0) {
         buf.append(chars, 0, count);
       }
       result = new char[buf.length()];
       buf.getChars(0, result.length, result, 0);
     }
   } catch (IOException e) {
     log.error("Compilation error", e);
   } finally {
     if (is != null) {
       try {
         is.close();
       } catch (IOException exc) {
         // Ignore
       }
     }
   }
   return result;
 }
예제 #3
0
 private void formatDate(final long now, final StringBuffer sbuf) {
   final int millis = (int) (now % 1000);
   final long rounded = now - millis;
   if (rounded != lastTimeMillis) {
     synchronized (calendar) {
       final int start = sbuf.length();
       calendar.setTimeInMillis(rounded);
       sbuf.append(calendar.get(Calendar.YEAR));
       sbuf.append('-');
       sbuf.append(toTwoDigits(calendar.get(Calendar.MONTH) + 1));
       sbuf.append('-');
       sbuf.append(toTwoDigits(calendar.get(Calendar.DAY_OF_MONTH)));
       sbuf.append(' ');
       sbuf.append(toTwoDigits(calendar.get(Calendar.HOUR_OF_DAY)));
       sbuf.append(':');
       sbuf.append(toTwoDigits(calendar.get(Calendar.MINUTE)));
       sbuf.append(':');
       sbuf.append(toTwoDigits(calendar.get(Calendar.SECOND)));
       sbuf.append(',');
       sbuf.getChars(start, sbuf.length(), lastTimeString, 0);
       lastTimeMillis = rounded;
     }
   } else {
     sbuf.append(lastTimeString);
   }
   sbuf.append(String.format("%03d", millis));
 }
예제 #4
0
  @Override
  public int read(char[] destBuffer, int destOffset, int destCount) throws IOException {
    int count = 0;
    int available = buffer.length() - offset;

    if (available == 0) {
      if (iterator.hasNext()) {
        iterator.next();
        processCurrentSegment();
        available = buffer.length() - offset;
      } else {
        count = -1;
      }
    }

    if (available > 0) {
      count = Math.min(destCount, available);
      buffer.getChars(offset, offset + count, destBuffer, destOffset);
      offset += count;
      if (offset == buffer.length()) {
        offset = 0;
        buffer.setLength(0);
      }
    }

    return count;
  }
예제 #5
0
 private static void uppercaseFirstLetter(final StringBuffer buf) {
   if (buf.length() > 1) {
     char[] firstLetter = new char[1];
     buf.getChars(0, 1, firstLetter, 0);
     buf.setCharAt(0, Character.toUpperCase(firstLetter[0]));
   }
 }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.compiler.lookup.Binding#shortReadableName()
  */
 public char[] shortReadableName() {
   switch (this.boundKind) {
     case Wildcard.UNBOUND:
       return TypeConstants.WILDCARD_NAME;
     case Wildcard.EXTENDS:
       if (this.otherBounds == null)
         return CharOperation.concat(
             TypeConstants.WILDCARD_NAME,
             TypeConstants.WILDCARD_EXTENDS,
             this.bound.shortReadableName());
       StringBuffer buffer = new StringBuffer(10);
       buffer.append(this.bound.shortReadableName());
       for (int i = 0, length = this.otherBounds.length; i < length; i++) {
         buffer.append('&').append(this.otherBounds[i].shortReadableName());
       }
       int length;
       char[] result = new char[length = buffer.length()];
       buffer.getChars(0, length, result, 0);
       return result;
     default: // SUPER
       return CharOperation.concat(
           TypeConstants.WILDCARD_NAME,
           TypeConstants.WILDCARD_SUPER,
           this.bound.shortReadableName());
   }
 }
예제 #7
0
 @Override
 public char[] nullAnnotatedReadableName(CompilerOptions options, boolean shortNames) {
   StringBuffer nameBuffer = new StringBuffer(10);
   appendNullAnnotation(nameBuffer, options);
   nameBuffer.append(this.sourceName());
   if (!this.inRecursiveFunction) { // CaptureBinding18 can be recursive indeed
     this.inRecursiveFunction = true;
     try {
       if (this.wildcard != null) {
         nameBuffer.append("of "); // $NON-NLS-1$
         nameBuffer.append(
             this.wildcard
                 .withoutToplevelNullAnnotation()
                 .nullAnnotatedReadableName(options, shortNames));
       } else if (this.lowerBound != null) {
         nameBuffer.append(" super "); // $NON-NLS-1$
         nameBuffer.append(this.lowerBound.nullAnnotatedReadableName(options, shortNames));
       } else if (this.firstBound != null) {
         nameBuffer.append(" extends "); // $NON-NLS-1$
         nameBuffer.append(this.firstBound.nullAnnotatedReadableName(options, shortNames));
         TypeBinding[] otherUpperBounds = this.otherUpperBounds();
         if (otherUpperBounds != NO_TYPES)
           nameBuffer.append(
               " & ..."); //$NON-NLS-1$ // only hint at more bounds, we currently don't evaluate
         // null annotations on otherUpperBounds
       }
     } finally {
       this.inRecursiveFunction = false;
     }
   }
   int nameLength = nameBuffer.length();
   char[] readableName = new char[nameLength];
   nameBuffer.getChars(0, nameLength, readableName, 0);
   return readableName;
 }
예제 #8
0
 /**
  * Similar to StringBuffer.getChars, version 1.3. Since JDK 1.2 implements StringBuffer.getChars
  * differently, this method is here to provide consistent results. To be removed after JDK 1.2
  * ceased to be the reference platform.
  *
  * @param src source string buffer
  * @param srcBegin offset to the start of the src to retrieve from
  * @param srcEnd offset to the end of the src to retrieve from
  * @param dst char array to store the retrieved chars
  * @param dstBegin offset to the start of the destination char array to store the retrieved chars
  */
 public static void getChars(
     StringBuffer src, int srcBegin, int srcEnd, char dst[], int dstBegin) {
   if (srcBegin == srcEnd) {
     return;
   }
   src.getChars(srcBegin, srcEnd, dst, dstBegin);
 }
 /*
  * declaringUniqueKey : genericTypeSignature
  * p.X<T> { ... } --> Lp/X;:TT;
  * p.X { <T> void foo() {...} } --> Lp/X;.foo()V:TT;
  */
 public char[] computeUniqueKey(boolean isLeaf) {
   StringBuffer buffer = new StringBuffer();
   Binding declaring = this.declaringElement;
   if (!isLeaf
       && declaring.kind()
           == Binding.METHOD) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=97902
     MethodBinding methodBinding = (MethodBinding) declaring;
     ReferenceBinding declaringClass = methodBinding.declaringClass;
     buffer.append(declaringClass.computeUniqueKey(false /*not a leaf*/));
     buffer.append(':');
     MethodBinding[] methods = declaringClass.methods();
     if (methods != null)
       for (int i = 0, length = methods.length; i < length; i++) {
         MethodBinding binding = methods[i];
         if (binding == methodBinding) {
           buffer.append(i);
           break;
         }
       }
   } else {
     buffer.append(declaring.computeUniqueKey(false /*not a leaf*/));
     buffer.append(':');
   }
   buffer.append(genericTypeSignature());
   int length = buffer.length();
   char[] uniqueKey = new char[length];
   buffer.getChars(0, length, uniqueKey, 0);
   return uniqueKey;
 }
예제 #10
0
 public char[] shortReadableName() {
   if (this.lowerBound == null && this.firstBound != null) {
     if (this.recursionLevel < 2) {
       try {
         this.recursionLevel++;
         if (this.upperBounds != null && this.upperBounds.length > 1) {
           StringBuffer sb = new StringBuffer();
           sb.append(this.upperBounds[0].shortReadableName());
           for (int i = 1; i < this.upperBounds.length; i++)
             sb.append('&').append(this.upperBounds[i].shortReadableName());
           int len = sb.length();
           char[] name = new char[len];
           sb.getChars(0, len, name, 0);
           return name;
         }
         return this.firstBound.shortReadableName();
       } finally {
         this.recursionLevel--;
       }
     } else {
       return this.originalName;
     }
   }
   return super.shortReadableName();
 }
예제 #11
0
  private static char[] readResponseData(InputStream stream, String encoding) {
    BufferedReader in = null;
    char[] data = null;
    try {
      StringBuffer buf = new StringBuffer();
      data = new char[1024];

      in = new BufferedReader(new InputStreamReader(stream, encoding));
      int charsRead;
      while ((charsRead = in.read(data)) != -1) {
        buf.append(data, 0, charsRead);
      }
      data = new char[buf.length()];
      buf.getChars(0, data.length, data, 0);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        in.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return data != null ? data : null;
  }
 @Override
 public char[] nullAnnotatedReadableName(CompilerOptions options, boolean shortNames) {
   StringBuffer nameBuffer = new StringBuffer(10);
   appendNullAnnotation(nameBuffer, options);
   nameBuffer.append(this.sourceName());
   if (!this.inRecursiveFunction) {
     this.inRecursiveFunction = true;
     try {
       if (this.superclass != null && TypeBinding.equalsEquals(this.firstBound, this.superclass)) {
         nameBuffer
             .append(" extends ")
             .append(
                 this.superclass.nullAnnotatedReadableName(options, shortNames)); // $NON-NLS-1$
       }
       if (this.superInterfaces != null && this.superInterfaces != Binding.NO_SUPERINTERFACES) {
         if (TypeBinding.notEquals(this.firstBound, this.superclass)) {
           nameBuffer.append(" extends "); // $NON-NLS-1$
         }
         for (int i = 0, length = this.superInterfaces.length; i < length; i++) {
           if (i > 0 || TypeBinding.equalsEquals(this.firstBound, this.superclass)) {
             nameBuffer.append(" & "); // $NON-NLS-1$
           }
           nameBuffer.append(
               this.superInterfaces[i].nullAnnotatedReadableName(options, shortNames));
         }
       }
     } finally {
       this.inRecursiveFunction = false;
     }
   }
   int nameLength = nameBuffer.length();
   char[] readableName = new char[nameLength];
   nameBuffer.getChars(0, nameLength, readableName, 0);
   return readableName;
 }
예제 #13
0
 public char[] nullAnnotatedReadableName(CompilerOptions options, boolean shortNames) {
   StringBuffer buffer = new StringBuffer(10);
   appendNullAnnotation(buffer, options);
   switch (this.boundKind) {
     case Wildcard.UNBOUND:
       buffer.append(TypeConstants.WILDCARD_NAME);
       break;
     case Wildcard.EXTENDS:
       if (this.otherBounds == null) {
         buffer.append(TypeConstants.WILDCARD_NAME).append(TypeConstants.WILDCARD_EXTENDS);
         buffer.append(this.bound.nullAnnotatedReadableName(options, shortNames));
       } else {
         buffer.append(this.bound.nullAnnotatedReadableName(options, shortNames));
         for (int i = 0, length = this.otherBounds.length; i < length; i++) {
           buffer
               .append('&')
               .append(this.otherBounds[i].nullAnnotatedReadableName(options, shortNames));
         }
       }
       break;
     default: // SUPER
       buffer
           .append(TypeConstants.WILDCARD_NAME)
           .append(TypeConstants.WILDCARD_SUPER)
           .append(this.bound.nullAnnotatedReadableName(options, shortNames));
   }
   int length;
   char[] result = new char[length = buffer.length()];
   buffer.getChars(0, length, result, 0);
   return result;
 }
예제 #14
0
  /**
   * Creates a new instance of a <CODE>CharSequence</CODE>, loading the sequence data from the
   * <CODE>Reader</CODE> input stream.
   *
   * @param reader source of characters for this sequence
   * @throws IOException if an I/O exception occurs when reading the input
   * @throws InvalidSequenceException if the input does not contain a valid sequence
   */
  public CharSequence(Reader reader) throws IOException, InvalidSequenceException {
    int ch;
    char c;

    BufferedReader input = new BufferedReader(reader);

    StringBuffer buf = new StringBuffer();

    // read characters
    while ((ch = input.read()) != -1) {
      // conver to char
      c = (char) ch;

      // skip line if comment character is found
      if (c == COMMENT_CHAR) input.readLine();

      // accept letters only
      else if (Character.isLetter(c)) buf.append(c);

      // anything else, except whitespaces, will throw an exception
      else if (!Character.isWhitespace(c))
        throw new InvalidSequenceException("Sequences can contain letters only.");
    }

    // check if read anything!
    if (buf.length() > 0) sequence = new char[buf.length()];
    else throw new InvalidSequenceException("Empty sequence.");

    // copy data to
    buf.getChars(0, buf.length(), sequence, 0);
  }
예제 #15
0
 /**
  * Get Base64 encoded characters as an array.
  *
  * @return Base64 encoded characters as an array.
  */
 public char[] getCharArray() {
   if (_octets > 0) {
     encodeWithPadding();
   }
   char[] chars = new char[_stream.length()];
   if (_stream.length() > 0) {
     _stream.getChars(0, _stream.length(), chars, 0);
   }
   return chars;
 }
예제 #16
0
 @Override
 public char[] computeUniqueKey(boolean isLeaf) {
   StringBuffer buffer = new StringBuffer();
   buffer.append(TypeConstants.CAPTURE18);
   buffer.append('{').append(this.position).append('#').append(this.captureID).append('}');
   buffer.append(';');
   int length = buffer.length();
   char[] uniqueKey = new char[length];
   buffer.getChars(0, length, uniqueKey, 0);
   return uniqueKey;
 }
  private char[] getCurrentBuffer(char[] newToken) {
    if (currentPhrase == null) currentPhrase = new StringBuffer();
    if (newToken != null && newToken.length > 0) {
      if (currentPhrase.length() > 0) currentPhrase.append(' ');
      currentPhrase.append(newToken);
    }

    char[] currentBuff = new char[currentPhrase.length()];
    currentPhrase.getChars(0, currentPhrase.length(), currentBuff, 0);
    return currentBuff;
  }
  /**
   * Appends to <code>sbuf</code> the time in the format "HH:mm:ss,SSS" for example, "15:49:37,459"
   *
   * @param date the date to format
   * @param sbuf the string buffer to write to
   * @param fieldPosition remains untouched
   */
  public StringBuffer format(Date date, StringBuffer sbuf, FieldPosition fieldPosition) {

    long now = date.getTime();
    int millis = (int) (now % 1000);

    if ((now - millis) != previousTime || previousTimeWithoutMillis[0] == 0) {
      // We reach this point at most once per second
      // across all threads instead of each time format()
      // is called. This saves considerable CPU time.

      calendar.setTime(date);

      int start = sbuf.length();

      int hour = calendar.get(Calendar.HOUR_OF_DAY);
      if (hour < 10) {
        sbuf.append('0');
      }
      sbuf.append(hour);
      sbuf.append(':');

      int mins = calendar.get(Calendar.MINUTE);
      if (mins < 10) {
        sbuf.append('0');
      }
      sbuf.append(mins);
      sbuf.append(':');

      int secs = calendar.get(Calendar.SECOND);
      if (secs < 10) {
        sbuf.append('0');
      }
      sbuf.append(secs);
      sbuf.append(',');

      // store the time string for next time to avoid recomputation
      sbuf.getChars(start, sbuf.length(), previousTimeWithoutMillis, 0);

      previousTime = now - millis;
    } else {
      sbuf.append(previousTimeWithoutMillis);
    }

    if (millis < 100) {
      sbuf.append('0');
    }
    if (millis < 10) {
      sbuf.append('0');
    }

    sbuf.append(millis);
    return sbuf;
  }
예제 #19
0
 public char[] signableName() {
   if (this.wildcard != null) {
     StringBuffer buffer = new StringBuffer(10);
     buffer
         .append(TypeConstants.WILDCARD_CAPTURE_SIGNABLE_NAME_SUFFIX)
         .append(this.wildcard.readableName());
     int length = buffer.length();
     char[] name = new char[length];
     buffer.getChars(0, length, name, 0);
     return name;
   }
   return super.readableName();
 }
예제 #20
0
 /*
  * sourceTypeKey ! wildcardKey position semi-colon
  * p.X { capture of ? } --> !*123; (Lp/X; in declaring type except if leaf)
  * p.X { capture of ? extends p.Y } --> !+Lp/Y;123; (Lp/X; in declaring type except if leaf)
  */
 public char[] computeUniqueKey(boolean isLeaf) {
   StringBuffer buffer = new StringBuffer();
   if (isLeaf) {
     buffer.append(this.sourceType.computeUniqueKey(false /*not a leaf*/));
     buffer.append('&');
   }
   buffer.append(TypeConstants.WILDCARD_CAPTURE);
   buffer.append(this.wildcard.computeUniqueKey(false /*not a leaf*/));
   buffer.append(this.position);
   buffer.append(';');
   int length = buffer.length();
   char[] uniqueKey = new char[length];
   buffer.getChars(0, length, uniqueKey, 0);
   return uniqueKey;
 }
 /** T::Ljava/util/Map;:Ljava/io/Serializable; T:LY<TT;> */
 public char[] genericSignature() {
   StringBuffer sig = new StringBuffer(10);
   sig.append(this.sourceName).append(':');
   int interfaceLength = this.superInterfaces == null ? 0 : this.superInterfaces.length;
   if (interfaceLength == 0 || TypeBinding.equalsEquals(this.firstBound, this.superclass)) {
     if (this.superclass != null) sig.append(this.superclass.genericTypeSignature());
   }
   for (int i = 0; i < interfaceLength; i++) {
     sig.append(':').append(this.superInterfaces[i].genericTypeSignature());
   }
   int sigLength = sig.length();
   char[] genericSignature = new char[sigLength];
   sig.getChars(0, sigLength, genericSignature, 0);
   return genericSignature;
 }
예제 #22
0
  /**
   * This method is used by {@link
   * org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CallinMethodMappingsAttribute
   * CallinMethodMappingsAttribute} for decoding a mapping from its bytecode attribute.
   *
   * @param method
   * @return the bytecode level signature of the given method (yet retrenched)
   */
  public static char[] signature(MethodBinding method, WeavingScheme weavingScheme) {

    StringBuffer buffer = new StringBuffer();
    buffer.append('(');
    // synthetic args for static role method?
    MethodBinding orig =
        method.copyInheritanceSrc != null
            ? method.copyInheritanceSrc
            : method; // normalize to copyInhSrc so reading a callin-attr. from bytes can more
    // easily find the method
    if (weavingScheme == WeavingScheme.OTDRE && orig.declaringClass.isRole() && orig.isStatic()) {
      buffer.append('I');
      buffer.append(String.valueOf(orig.declaringClass.enclosingType().signature()));
    }
    // manual retrenching?
    boolean shouldRetrench = weavingScheme == WeavingScheme.OTRE && method.isCallin();
    int offset = shouldRetrench ? MethodSignatureEnhancer.getEnhancingArgLen(weavingScheme) : 0;
    int paramLen = method.parameters.length;
    for (int i = offset; i < paramLen; i++) {
      // 'weaken' to that erasure that was used in the tsuper version:
      TypeBinding targetParameter = method.getCodeGenType(i);
      buffer.append(targetParameter.signature());
    }
    buffer.append(')');
    TypeBinding sourceReturnType =
        shouldRetrench ? MethodModel.getReturnType(method) : method.returnType;
    // 'weaken' to that erasure that was used in the tsuper version:
    MethodBinding tsuperOriginal =
        (method.tagBits & TagBits.IsCopyOfParameterized) != 0
            ? method.copyInheritanceSrc.original()
            : null;
    TypeBinding returnType =
        (tsuperOriginal != null
                && tsuperOriginal.returnType.isTypeVariable()
                && !sourceReturnType.isTypeVariable())
            ? tsuperOriginal.returnType
            : sourceReturnType;
    if (returnType.isTypeVariable() && method instanceof ParameterizedGenericMethodBinding)
      returnType =
          ((ParameterizedGenericMethodBinding) method)
              .reverseSubstitute((TypeVariableBinding) returnType);
    buffer.append(returnType.erasure().signature());
    int nameLength = buffer.length();
    char[] signature = new char[nameLength];
    buffer.getChars(0, nameLength, signature, 0);

    return signature;
  }
 public char[] method_256() {
   StringBuffer var1 = new StringBuffer(10);
   var1.append(this.sourceName).append(':');
   int var2 = this.superInterfaces == null ? 0 : this.superInterfaces.length;
   if ((var2 == 0 || this.firstBound == this.superclass) && this.superclass != null) {
     var1.append(this.superclass.genericTypeSignature());
   }
   int var3;
   for (var3 = 0; var3 < var2; ++var3) {
     var1.append(':').append(this.superInterfaces[var3].genericTypeSignature());
   }
   var3 = var1.length();
   char[] var4 = new char[var3];
   var1.getChars(0, var3, var4, 0);
   return var4;
 }
예제 #24
0
  public VMCodeLine(
      StringBuffer buff,
      Vector<MarkUp> markUpVector,
      SourceCoords sc,
      Set<TagSetInterface> tagSets) {
    chars = new char[buff.length()];
    if (buff.length() > 0) // Work around jview bug!
    buff.getChars(0, buff.length(), chars, 0);

    markUp = new MarkUp[markUpVector.size()];
    for (int i = 0, sz = markUpVector.size(); i < sz; ++i) {
      markUp[i] = markUpVector.elementAt(i);
    }

    coords = sc;
    this.tagSets = tagSets;
  }
예제 #25
0
파일: StringFunc.java 프로젝트: ivandr/MVD
  /**
   * Дополняет строку слева
   *
   * @param str - строка
   * @param len - целевая длина
   * @param ch - символ - заполнитель
   * @return - целевая строка
   */
  public static String padl(String str, int len, char ch) {
    StringBuffer sch = new StringBuffer();
    int strlen = str.length();
    while ((strlen + sch.length()) < len) {
      sch = sch.append(ch); // concat(new String(ach));
    }
    sch = sch.append(str);

    int schlen = sch.length();
    if (schlen > len) {
      char[] arr = new char[schlen];
      sch.getChars(0, schlen, arr, 0);
      return String.copyValueOf(arr, schlen - len, len);
    } else {
      return sch.toString();
    }
  }
예제 #26
0
 String getWord() {
   skipWhite();
   boolean backslash = false;
   boolean quote = false;
   StringBuffer val = new StringBuffer();
   int end = 0;
   loop:
   for (; pos < length; pos++) {
     if (backslash) {
       backslash = false;
       val.append(s.charAt(pos));
     } else {
       char c = s.charAt(pos);
       switch (c) {
         case '"':
           quote = !quote;
           end = val.length();
           break;
         case '\\':
           backslash = true;
           break;
         case ',':
         case ':':
         case ';':
         case '=':
           if (!quote) {
             break loop;
           }
           // Fall through
         default:
           val.append(c);
           if (!Character.isWhitespace(c)) {
             end = val.length();
           }
           break;
       }
     }
   }
   if (quote || backslash || end == 0) {
     return null;
   }
   char[] res = new char[end];
   val.getChars(0, end, res, 0);
   return new String(res);
 }
  public void writeCoordinates(CoordinateSequence c, ContentHandler output) throws SAXException {

    output.startElement("", "coordinates", "coordinates", atts);

    final int coordCount = c.size();
    // used to check whether the coordseq handles a third dimension or not
    final int coordSeqDimension = c.getDimension();
    double x, y, z;
    // write down a coordinate at a time
    for (int i = 0, n = coordCount; i < n; i++) {
      x = c.getOrdinate(i, 0);
      y = c.getOrdinate(i, 1);

      // clear the buffer
      coordBuff.setLength(0);

      // format x into buffer and append delimiter
      formatDecimal(x, coordBuff);
      coordBuff.append(coordinateDelimiter);
      // format y into buffer
      formatDecimal(y, coordBuff);

      if (coordSeqDimension > 2 && !Double.isNaN(c.getOrdinate(i, 2))) {
        coordBuff.append(coordinateDelimiter);
        formatDecimal(c.getOrdinate(i, 2), coordBuff);
      }

      // if there is another coordinate, tack on a tuple delimiter
      if (i + 1 < coordCount) {
        coordBuff.append(tupleDelimiter);
      }

      // make sure our character buffer is big enough
      if (coordBuff.length() > buff.length) {
        buff = new char[coordBuff.length()];
      }

      // copy the characters
      coordBuff.getChars(0, coordBuff.length(), buff, 0);

      // finally, output
      output.characters(buff, 0, coordBuff.length());
    }
    output.endElement(null, "coordinates", "coordinates");
  }
 /*
  * parameterizedDeclaringUniqueKey dot selector originalMethodGenericSignature percent typeArguments
  * p.X<U> { <T> void bar(T t, U u) { new X<String>().bar(this, "") } } --> Lp/X<Ljava/lang/String;>;.bar<T:Ljava/lang/Object;>(TT;Ljava/lang/String;)V%<Lp/X;>
  */
 public char[] computeUniqueKey(boolean isLeaf) {
   StringBuffer buffer = new StringBuffer();
   buffer.append(this.originalMethod.computeUniqueKey(false /*not a leaf*/));
   buffer.append('%');
   buffer.append('<');
   if (!this.isRaw) {
     int length = this.typeArguments.length;
     for (int i = 0; i < length; i++) {
       TypeBinding typeArgument = this.typeArguments[i];
       buffer.append(typeArgument.computeUniqueKey(false /*not a leaf*/));
     }
   }
   buffer.append('>');
   int resultLength = buffer.length();
   char[] result = new char[resultLength];
   buffer.getChars(0, resultLength, result, 0);
   return result;
 }
예제 #29
0
파일: Support.java 프로젝트: floatin/Weave
  /**
   * Update the SQL string and replace the ? markers with parameter names eg @P0, @P1 etc.
   *
   * @param sql the SQL containing markers to substitute
   * @param list the parameter list
   * @return the modified SQL as a <code>String</code>
   */
  static String substituteParamMarkers(String sql, ParamInfo[] list) {
    // A parameter can have at most 8 characters: " @P" plus at most 4
    // digits plus " ". We subtract the "?" placeholder, that's at most
    // 7 extra characters needed for each parameter.
    char[] buf = new char[sql.length() + list.length * 7];
    int bufferPtr = 0; // Output buffer pointer
    int start = 0; // Input string pointer
    StringBuffer number = new StringBuffer(4);

    for (int i = 0; i < list.length; i++) {
      int pos = list[i].markerPos;

      if (pos > 0) {
        sql.getChars(start, pos, buf, bufferPtr);
        bufferPtr += (pos - start);
        start = pos + 1;

        // Append " @P"
        buf[bufferPtr++] = ' ';
        buf[bufferPtr++] = '@';
        buf[bufferPtr++] = 'P';

        // Append parameter number
        // Rather complicated, but it's the only way in which no
        // unnecessary objects are created
        number.setLength(0);
        number.append(i);
        number.getChars(0, number.length(), buf, bufferPtr);
        bufferPtr += number.length();

        // Append " "
        buf[bufferPtr++] = ' ';
      }
    }

    if (start < sql.length()) {
      sql.getChars(start, sql.length(), buf, bufferPtr);
      bufferPtr += (sql.length() - start);
    }

    return new String(buf, 0, bufferPtr);
  }
  public char[] getFileContents(File file) {
    // char array to store the file contents in
    char[] contents = null;
    try {
      BufferedReader br = new BufferedReader(new FileReader(file));
      StringBuffer sb = new StringBuffer();
      String line = "";
      while ((line = br.readLine()) != null) {
        // append the content and the lost new line.
        sb.append(line + "\n");
      }
      contents = new char[sb.length()];
      sb.getChars(0, sb.length() - 1, contents, 0);

      assert (contents.length > 0);
    } catch (IOException e) {
      System.out.println(e.getMessage());
    }

    return contents;
  }