private static void generateNameByString(
      Set<String> possibleNames,
      String value,
      NameValidator validator,
      boolean forStaticVariable,
      Project project) {
    if (!JavaPsiFacade.getInstance(project).getNameHelper().isIdentifier(value)) return;
    if (forStaticVariable) {
      StringBuilder buffer = new StringBuilder(value.length() + 10);
      char[] chars = new char[value.length()];
      value.getChars(0, value.length(), chars, 0);
      boolean wasLow = Character.isLowerCase(chars[0]);

      buffer.append(Character.toUpperCase(chars[0]));
      for (int i = 1; i < chars.length; i++) {
        if (Character.isUpperCase(chars[i])) {
          if (wasLow) {
            buffer.append('_');
            wasLow = false;
          }
        } else {
          wasLow = true;
        }

        buffer.append(Character.toUpperCase(chars[i]));
      }
      possibleNames.add(validator.validateName(buffer.toString(), true));
    } else {
      possibleNames.add(validator.validateName(value, true));
    }
  }
Example #2
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;
  }
Example #3
1
  static Integer helper(int i, StringBuilder sb, String s) {
    if (i == s.length()) {
      return decode(sb.toString());
    }

    if (!Character.isLetter(s.charAt(i))) {
      sb.append(s.charAt(i));
      Integer result = helper(i + 1, sb, s);
      if (result != null) {
        return result;
      }
    } else {
      char ch = s.charAt(i);
      sb.append(Character.toUpperCase(ch));
      Integer result = helper(i + 1, sb, s);
      if (result != null) {
        return result;
      }
      sb.deleteCharAt(sb.length() - 1);

      sb.append(Character.toLowerCase(ch));
      result = helper(i + 1, sb, s);
      if (result != null) {
        return result;
      }
      sb.deleteCharAt(sb.length() - 1);
    }
    return null;
  }
 private List getSubpaths(String paramString) {
   int i = 0;
   int j = paramString.length();
   ArrayList localArrayList = new ArrayList();
   while (i < j) {
     while ((i < j) && (Character.isWhitespace(paramString.charAt(i)))) i++;
     if (i >= j) continue;
     int k = i;
     int m = k;
     String str = null;
     while (i < j) {
       char c = paramString.charAt(i);
       if ((c == '\\') && (i + 1 < j) && (paramString.charAt(i + 1) == ' ')) {
         if (str == null) str = paramString.substring(m, i);
         else str = str + paramString.substring(m, i);
         i++;
         m = i;
       } else {
         if (Character.isWhitespace(c)) break;
       }
       i++;
     }
     if (m != i)
       if (str == null) str = paramString.substring(m, i);
       else str = str + paramString.substring(m, i);
     localArrayList.add(str);
   }
   return localArrayList;
 }
Example #5
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;
 }
Example #6
0
 /**
  * @param number1
  * @param number2
  * @return
  */
 public static String addNums(String number1, String number2) {
   char[] num1char = number1.toCharArray();
   char[] num2char = number2.toCharArray();
   if (num1char.length > num2char.length) {
     num2char = formatLength(num1char, num2char);
   } else if (num1char.length < num2char.length) {
     num1char = formatLength(num2char, num1char);
   }
   final char[] addition = new char[num1char.length + 1];
   char carry = '0';
   for (int i = num1char.length - 1; i >= 0; i--) {
     int sum =
         Character.getNumericValue(num1char[i])
             + Character.getNumericValue(num2char[i])
             + Character.getNumericValue(carry);
     char[] csum = String.valueOf(sum).toCharArray();
     carry = '0';
     if (csum.length > 1 && i == 0) {
       addition[i + 1] = csum[1];
       addition[0] = csum[0];
     } else if (csum.length > 1) {
       carry = csum[0];
       addition[i + 1] = csum[1];
     } else {
       addition[i + 1] = csum[0];
     }
   }
   return String.valueOf(addition);
 }
 public static int correctSubStringLen(String input, int len) {
   if (Character.isHighSurrogate(input.charAt(len - 1))) {
     assert input.length() >= len + 1 && Character.isLowSurrogate(input.charAt(len));
     return len + 1;
   }
   return len;
 }
Example #8
0
 /**
  * Tests if the string ends with the specified suffix.
  *
  * @param text the string to test.
  * @param suffix the suffix.
  * @return <code>true</code> if the character sequence represented by the argument is a suffix of
  *     the character sequence represented by this object; <code>false</code> otherwise. Note that
  *     the result will be <code>true</code> if the suffix is the empty string or is equal to this
  *     <code>String</code> object as determined by the {@link #equals(Object)} method. If the text
  *     or suffix argument is null <code>false</code> is returned.
  */
 public static boolean endsWithIgnoreCase(final String text, final String suffix) {
   if (isEmpty(text)) {
     return false;
   }
   if (suffix == null) {
     return false;
   }
   int textLength = text.length();
   int suffixLength = suffix.length();
   if (suffixLength == 0) {
     return true;
   }
   if (suffixLength > textLength) {
     return false;
   }
   int offset = textLength - suffixLength;
   char[] chArray = suffix.toCharArray();
   for (int i = 0; i != chArray.length; ++i) {
     char ch1 = chArray[i];
     char ch2 = text.charAt(offset + i);
     if (ch1 == ch2 || Character.toLowerCase(ch1) == Character.toLowerCase(ch2)) {
       // continue
     } else {
       return false;
     }
   }
   return true;
 }
 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;
 }
Example #10
0
 /**
  * Returns the Unicode code point of the character at the given index.
  *
  * <p>Unlike {@link Character#codePointAt(CharSequence, int)} or {@link String#codePointAt(int)}
  * this method will never fail silently when encountering an invalid surrogate pair.
  *
  * <p>The behaviour of this method is as follows:
  *
  * <ol>
  *   <li>If {@code index >= end}, {@link IndexOutOfBoundsException} is thrown.
  *   <li><b>If the character at the specified index is not a surrogate, it is returned.</b>
  *   <li>If the first character was a high surrogate value, then an attempt is made to read the
  *       next character.
  *       <ol>
  *         <li><b>If the end of the sequence was reached, the negated value of the trailing high
  *             surrogate is returned.</b>
  *         <li><b>If the next character was a valid low surrogate, the code point value of the
  *             high/low surrogate pair is returned.</b>
  *         <li>If the next character was not a low surrogate value, then {@link
  *             IllegalArgumentException} is thrown.
  *       </ol>
  *   <li>If the first character was a low surrogate value, {@link IllegalArgumentException} is
  *       thrown.
  * </ol>
  *
  * @param seq the sequence of characters from which to decode the code point
  * @param index the index of the first character to decode
  * @param end the index beyond the last valid character to decode
  * @return the Unicode code point for the given index or the negated value of the trailing high
  *     surrogate character at the end of the sequence
  */
 protected static final int codePointAt(CharSequence seq, int index, int end) {
   if (index < end) {
     char c1 = seq.charAt(index++);
     if (c1 < Character.MIN_HIGH_SURROGATE || c1 > Character.MAX_LOW_SURROGATE) {
       // Fast path (first test is probably all we need to do)
       return c1;
     } else if (c1 <= Character.MAX_HIGH_SURROGATE) {
       // If the high surrogate was the last character, return its inverse
       if (index == end) {
         return -c1;
       }
       // Otherwise look for the low surrogate following it
       char c2 = seq.charAt(index);
       if (Character.isLowSurrogate(c2)) {
         return Character.toCodePoint(c1, c2);
       }
       throw new IllegalArgumentException(
           "Expected low surrogate but got char '"
               + c2
               + "' with value "
               + (int) c2
               + " at index "
               + index);
     } else {
       throw new IllegalArgumentException(
           "Unexpected low surrogate character '"
               + c1
               + "' with value "
               + (int) c1
               + " at index "
               + (index - 1));
     }
   }
   throw new IndexOutOfBoundsException("Index exceeds specified range");
 }
 public String generateValidIdString(String base) {
   if (base == null) {
     throw new IllegalArgumentException(base);
   }
   int n = base.length();
   if (n < 1) {
     throw new IllegalArgumentException(base);
   }
   StringBuilder newId = new StringBuilder();
   for (int i = 0; i < n; i++) {
     char c = base.charAt(i);
     if (i == 0) {
       if (!Character.isLetter(c) && (c != '_')) {
         newId.append("_");
       } else {
         newId.append(c);
       }
     } else {
       if (!Character.isLetter(c) && !Character.isDigit(c) && (c != '-') && (c != '_')) {
         newId.append("_");
       } else {
         newId.append(c);
       }
     }
   }
   return newId.toString();
 }
Example #12
0
  private static String createRegexForReplace(String toFind) {
    char[] find = toFind.toCharArray();
    StringBuilder regexString = new StringBuilder();
    for (char f : find) {
      int d = f;
      if ((d >= 65 && d <= 90) || (d >= 97 && d <= 122)) {
        regexString.append("[");
        regexString.append(Character.toString((char) d));
        int temp = d;
        if (Character.isLowerCase(f)) {
          temp = d - 32;
        } else {
          temp = d + 32;
        }
        regexString.append(Character.toString((char) temp));
        regexString.append("]");
      } else if (d == 32) {

        regexString.append("[\\s]");
      } else {
        regexString.append("[");
        regexString.append(f);
        regexString.append("]");
      }
    }
    return regexString.toString();
  }
  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);
  }
Example #14
0
 /*
  * jan = 9 + 0 + 13 = 22 feb = 5 + 4 + 1 = 10 mar = 12 + 0 + 17 = 29 apr = 0
  * + 15 + 17 = 32 may = 12 + 0 + 24 = 36 jun = 9 + 20 + 13 = 42 jul = 9 + 20
  * + 11 = 40 aug = 0 + 20 + 6 = 26 sep = 18 + 4 + 15 = 37 oct = 14 + 2 + 19
  * = 35 nov = 13 + 14 + 21 = 48 dec = 3 + 4 + 2 = 9
  */
 private static int getMonth(String monthString) {
   int hash =
       Character.toLowerCase(monthString.charAt(0))
           + Character.toLowerCase(monthString.charAt(1))
           + Character.toLowerCase(monthString.charAt(2))
           - 3 * 'a';
   switch (hash) {
     case 22:
       return Calendar.JANUARY;
     case 10:
       return Calendar.FEBRUARY;
     case 29:
       return Calendar.MARCH;
     case 32:
       return Calendar.APRIL;
     case 36:
       return Calendar.MAY;
     case 42:
       return Calendar.JUNE;
     case 40:
       return Calendar.JULY;
     case 26:
       return Calendar.AUGUST;
     case 37:
       return Calendar.SEPTEMBER;
     case 35:
       return Calendar.OCTOBER;
     case 48:
       return Calendar.NOVEMBER;
     case 9:
       return Calendar.DECEMBER;
     default:
       throw new IllegalArgumentException();
   }
 }
Example #15
0
 /**
  * Encodes byte into its quoted-printable representation.
  *
  * @param b byte to encode
  * @param buffer the buffer to write to
  */
 private static final void encodeQuotedPrintable(int b, ByteArrayOutputStream buffer) {
   buffer.write(ESCAPE_CHAR);
   char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16));
   char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
   buffer.write(hex1);
   buffer.write(hex2);
 }
Example #16
0
    private boolean compare_Character(int operation, char charval, Object value2) {
      if (operation == SUBSTRING) {
        return false;
      }
      char charval2;
      try {
        charval2 = ((String) value2).charAt(0);
      } catch (IndexOutOfBoundsException e) {
        return false;
      }

      switch (operation) {
        case EQUAL:
          {
            return charval == charval2;
          }
        case APPROX:
          {
            return (charval == charval2)
                || (Character.toUpperCase(charval) == Character.toUpperCase(charval2))
                || (Character.toLowerCase(charval) == Character.toLowerCase(charval2));
          }
        case GREATER:
          {
            return charval >= charval2;
          }
        case LESS:
          {
            return charval <= charval2;
          }
      }
      return false;
    }
  private void finishComposition() {
    int len = buffer.length();
    if (len == 6 && format != SPECIAL_ESCAPE) {
      char codePoint = (char) getCodePoint(buffer, 2, 5);
      if (Character.isValidCodePoint(codePoint) && codePoint != 0xFFFF) {
        buffer.setLength(0);
        buffer.append(codePoint);
        sendCommittedText();
        return;
      }
    } else if (len == 8 && format == SPECIAL_ESCAPE) {
      int codePoint = getCodePoint(buffer, 2, 7);
      if (Character.isValidCodePoint(codePoint) && codePoint != 0xFFFF) {
        buffer.setLength(0);
        buffer.appendCodePoint(codePoint);
        sendCommittedText();
        return;
      }
    } else if (len == 12 && format == SURROGATE_PAIR) {
      char[] codePoint = {(char) getCodePoint(buffer, 2, 5), (char) getCodePoint(buffer, 8, 11)};
      if (Character.isHighSurrogate(codePoint[0]) && Character.isLowSurrogate(codePoint[1])) {
        buffer.setLength(0);
        buffer.append(codePoint);
        sendCommittedText();
        return;
      }
    }

    beep();
  }
Example #18
0
 /** NOTE: The sourceX2 is exclusive. */
 public void copyInterval(TerminalRow line, int sourceX1, int sourceX2, int destinationX) {
   final int x1 = line.findStartOfColumn(sourceX1);
   final int x2 = line.findStartOfColumn(sourceX2);
   boolean startingFromSecondHalfOfWideChar =
       (sourceX1 > 0 && line.wideDisplayCharacterStartingAt(sourceX1 - 1));
   final char[] sourceChars =
       (this == line) ? Arrays.copyOf(line.mText, line.mText.length) : line.mText;
   int latestNonCombiningWidth = 0;
   for (int i = x1; i < x2; i++) {
     char sourceChar = sourceChars[i];
     int codePoint =
         Character.isHighSurrogate(sourceChar)
             ? Character.toCodePoint(sourceChar, sourceChars[++i])
             : sourceChar;
     if (startingFromSecondHalfOfWideChar) {
       // Just treat copying second half of wide char as copying whitespace.
       codePoint = ' ';
       startingFromSecondHalfOfWideChar = false;
     }
     int w = WcWidth.width(codePoint);
     if (w > 0) {
       destinationX += latestNonCombiningWidth;
       sourceX1 += latestNonCombiningWidth;
       latestNonCombiningWidth = w;
     }
     setChar(destinationX, codePoint, line.getStyle(sourceX1));
   }
 }
  protected static String addUnderscores(String name, boolean pluralize) {
    StringBuffer buf = new StringBuffer(name.replace('.', '_'));
    for (int i = 1; i < buf.length() - 1; i++) {
      if (Character.isLowerCase(buf.charAt(i - 1))
          && Character.isUpperCase(buf.charAt(i))
          && Character.isLowerCase(buf.charAt(i + 1))) {
        buf.insert(i++, '_');
      }
    }

    if (pluralize) {
      String[] splitTableNameFragments = buf.toString().toLowerCase().split("_");

      StringBuffer buf2 = new StringBuffer();

      for (int i = 0; i < splitTableNameFragments.length; i++) {

        if (i < (splitTableNameFragments.length - 1)) {
          buf2.append(splitTableNameFragments[i]);
          buf2.append("_");
        } else {
          buf2.append(English.plural(splitTableNameFragments[i]));
        }
      }

      return buf2.toString().toUpperCase();
    }

    return buf.toString().toUpperCase();
  }
  private boolean add(char[] chars, V newValue, int offset, int length) {
    if (offset == length) {
      this.value = newValue;
      boolean wasAlreadyAKey = this.key != null;
      this.key = new String(chars);
      return !wasAlreadyAKey;
    }

    char nextChar = chars[offset];
    AbbreviationMap<V> child = (AbbreviationMap<V>) this.children.get(Character.valueOf(nextChar));
    if (child == null) {
      child = new AbbreviationMap<V>();
      this.children.put(Character.valueOf(nextChar), child);
    }

    boolean newKeyAdded = child.add(chars, newValue, offset + 1, length);

    if (newKeyAdded) {
      this.keysBeyond += 1;
    }
    if (this.key == null) {
      this.value = (this.keysBeyond > 1 ? null : newValue);
    }
    return newKeyAdded;
  }
Example #21
0
  /**
   * Segments the paragraph to sentences according to currently setup rules.
   *
   * <p>Bugfix for <a href="http://sourceforge.net/support/tracker.php?aid=1288742">issue
   * 1288742</a>: Sentences are returned without spaces in the beginning and at the end of a
   * sentence.
   *
   * <p>An additional list with space information is returned to be able to glue translation
   * together with the same spaces between them as in original paragraph.
   *
   * @param paragraph the paragraph text
   * @param spaces list to store information about spaces between sentences
   * @param brules list to store rules that account to breaks
   * @return list of sentences (String objects)
   */
  public static List<String> segment(
      Language lang, String paragraph, List<StringBuffer> spaces, List<Rule> brules) {
    List<String> segments = breakParagraph(lang, paragraph, brules);
    List<String> sentences = new ArrayList<String>(segments.size());
    if (spaces == null) spaces = new ArrayList<StringBuffer>();
    spaces.clear();
    for (String one : segments) {
      int len = one.length();
      int b = 0;
      StringBuffer bs = new StringBuffer();
      while (b < len && Character.isWhitespace(one.charAt(b))) {
        bs.append(one.charAt(b));
        b++;
      }

      int e = len - 1;
      StringBuffer es = new StringBuffer();
      while (e >= b && Character.isWhitespace(one.charAt(e))) {
        es.append(one.charAt(e));
        e--;
      }
      es.reverse();

      String trimmed = one.substring(b, e + 1);
      sentences.add(trimmed);
      if (spaces != null) {
        spaces.add(bs);
        spaces.add(es);
      }
    }
    return sentences;
  }
  @Override
  public boolean consume(CodeReader code, Lexer lexer) {
    if (!Character.isJavaIdentifierStart(code.peek())) {
      return false;
    }

    int line = code.getCursor().getLine();
    int column = code.getCursor().getColumn();
    while (Character.isJavaIdentifierPart(code.peek())) {
      tmpBuilder.append((char) code.pop());
    }

    String word = tmpBuilder.toString();

    TokenType keywordType = keywordsMap.get(word);
    Token token =
        tokenBuilder
            .setType(keywordType == null ? GenericTokenType.IDENTIFIER : keywordType)
            .setValueAndOriginalValue(word, word)
            .setURI(lexer.getURI())
            .setLine(line)
            .setColumn(column)
            .build();

    lexer.addToken(token);

    tmpBuilder.delete(0, tmpBuilder.length());

    return true;
  }
Example #23
0
 public Node toYamlNode(Representer representer) throws IOException {
   final Map values = new HashMap();
   final Method[] ems = data.getClass().getMethods();
   for (int i = 0, j = ems.length; i < j; i++) {
     if (ems[i].getParameterTypes().length == 0) {
       final String name = ems[i].getName();
       if (name.equals("getClass")) {
         continue;
       }
       String pname = null;
       if (name.startsWith("get")) {
         pname = "" + Character.toLowerCase(name.charAt(3)) + name.substring(4);
       } else if (name.startsWith("is")) {
         pname = "" + Character.toLowerCase(name.charAt(2)) + name.substring(3);
       }
       if (null != pname) {
         try {
           values.put(pname, ems[i].invoke(data, new Object[0]));
         } catch (final Exception exe) {
           values.put(pname, null);
         }
       }
     }
   }
   return representer.map(taguri(), values, false);
 }
  private int findalias(String sentence, int position) {

    int i = position - 1;
    int s = 0;

    while (i > 0) {
      char c = sentence.charAt(i);
      if (s == 0) {
        if (c == '.') {
          s = 1;
        } else {
          return -1;
        }
      } else if (s == 1) {
        if (Character.isLetterOrDigit(c)) {
          s = 2;
        } else {
          return -1;
        }
      } else if (s == 2) {
        if (!Character.isLetterOrDigit(c)) {
          if (Character.isWhitespace(c) || c == ')' || c == '(') {
            return i + 1;
          } else {
            return -1;
          }
        }
      }
      i--;
    }
    return -1;
  }
 /**
  * Returns the numeric {@code int} value of a {@code char}
  *
  * @param value the input {@code char} to be parsed
  * @return the numeric {@code int} value represented by the character.
  * @throws NumberFormatException in case character is not a digit
  */
 protected int extractDigit(char value) throws NumberFormatException {
   if (Character.isDigit(value)) {
     return Character.digit(value, DEC_RADIX);
   } else {
     throw log.getCharacterIsNotADigitException(value);
   }
 }
  /**
   * Creates a new word correction proposal.
   *
   * @param word the corrected word
   * @param arguments the problem arguments associated with the spelling problem
   * @param offset the offset in the document where to apply the proposal
   * @param length the length in the document to apply the proposal
   * @param context the invocation context for this proposal
   * @param relevance the relevance of this proposal
   */
  public WordCorrectionProposal(
      final String word,
      final String[] arguments,
      final int offset,
      final int length,
      final IInvocationContext context,
      final int relevance) {
    fWord =
        Character.isUpperCase(arguments[0].charAt(0))
            ? Character.toUpperCase(word.charAt(0)) + word.substring(1)
            : word;

    fOffset = offset;
    fLength = length;
    fContext = context;
    fRelevance = relevance;

    final StringBuffer buffer = new StringBuffer(80);

    buffer.append("...<br>"); // $NON-NLS-1$
    buffer.append(getHtmlRepresentation(arguments[1]));
    buffer.append("<b>"); // $NON-NLS-1$
    buffer.append(getHtmlRepresentation(fWord));
    buffer.append("</b>"); // $NON-NLS-1$
    buffer.append(getHtmlRepresentation(arguments[2]));
    buffer.append("<br>..."); // $NON-NLS-1$

    fLine = buffer.toString();
  }
Example #27
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;
  }
 /**
  * @ensures: if input file is read, a String is filled with words from file and searched in
  *     dictionary list, and if found increase words found counter, otherwise increase words not
  *     found. Otherwise error reading file
  */
 public void readFileOliver() {
   try {
     FileInputStream inf = new FileInputStream(new File("oliver.txt"));
     char let;
     String str = "";
     String key = "";
     int n = 0;
     while ((n = inf.read()) != -1) {
       let = (char) n;
       if (Character.isLetter(let)) {
         str += Character.toLowerCase(let);
       }
       if ((Character.isWhitespace(let) || let == '-') && !str.isEmpty()) {
         key = str;
         str = "";
         boolean a = dictionary[(int) key.charAt(0) - 97].contains(key);
         if (a == true) {
           counter = dictionary[(int) key.charAt(0) - 97].indexOf(key);
           counterWFound++;
           counterWFCompared += counter;
         } else {
           counter =
               dictionary[(int) key.charAt(0) - 97].indexOf(
                   dictionary[(int) key.charAt(0) - 97].getLast());
           counterWNotFound++;
           counterWNFCompared += counter;
         }
       }
     }
     inf.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
  public static String getOrthographyValue(String content) {
    if (content == null || content.isEmpty()) return null;

    Set<Integer> types = new HashSet<Integer>();

    for (int i = 1; i < content.length(); i++) {
      char c = content.charAt(i);
      types.add(Character.getType(c));
    }

    // we are ignoring spaces
    types.remove(Character.getType(' '));

    // we are ignoring CONTROL chars
    types.remove(Character.getType(':'));

    if (Character.getType(content.charAt(0)) == Character.UPPERCASE_LETTER) {
      if (lowerCaseTypesSet.containsAll(types)) return "upperInitial";
    }

    types.add(Character.getType(content.charAt(0)));

    if (upperCaseTypesSet.containsAll(types)) return "allCaps";

    if (lowerCaseTypesSet.containsAll(types)) return "lowercase";

    if (mixedCaseTypesSet.containsAll(types)) return "mixedCaps";

    return null;
  }
 public static String capitalizeFirstCharacter(String s) {
   if (s != null && s.isEmpty() == false && Character.isLowerCase(s.charAt(0))) {
     return Character.toUpperCase(s.charAt(0)) + s.substring(1);
   } else {
     return s;
   }
 }