protected int seekNextCaretLocation(int pos, boolean forward) {

    int dir = forward ? 1 : -1;
    int e = forward ? textLength : 0;
    if (pos == textLength) {
      --pos;
    }
    char prevChar = text[pos];
    while (pos != e && Character.isSpaceChar(prevChar)) {
      prevChar = text[pos += dir];
    }

    if (smartCaret) {
      for (int i = pos; i != e; i += dir) {
        char curChar = text[i];
        boolean caze = Character.isUpperCase(curChar) != Character.isUpperCase(prevChar);
        if (caze
            || Character.isSpaceChar(curChar) != Character.isSpaceChar(prevChar)
            || Character.isLetterOrDigit(curChar) != Character.isLetterOrDigit(prevChar)) {
          if ((pos + dir) != i || !Character.isLetterOrDigit(curChar)) {
            return i + (smartCaretCase && caze && Character.isUpperCase(prevChar) ? -dir : 0);
          }
        }
        prevChar = curChar;
      }
    }
    for (int i = pos; i != e; i += dir) {
      char curChar = text[i];
      if (Character.isSpaceChar(curChar) != Character.isSpaceChar(prevChar)) {
        return i;
      }
    }
    return forward ? textLength : 0;
  }
Beispiel #2
0
  private char swallowWhiteSpace(char c, PushbackReader pbr) throws java.io.IOException {
    // Hmm .. I need a separate check for '\n'.
    // Surprised it is not considered a space-character
    char separator = c;

    // Swallow white-space and hyphens
    while (true) {
      int i = pbr.read();
      if (i == -1) {
        break;
      } else {
        c = (char) i;
        if (c == '-') {
          separator = '-';
        } else if (c != '\n' && !Character.isSpaceChar(c)) {
          pbr.unread(i);
          break;
        }
      }
    }

    // Normalize all white-space sequences to a single space
    if (separator == '\n' || Character.isSpaceChar(separator)) separator = ' ';

    return separator;
  }
Beispiel #3
0
  private List<String> parseQuery(String query) {
    List<String> queries = new ArrayList<>();

    query = query.trim();

    int state = 0;
    StringBuilder current = new StringBuilder();
    for (int i = 0; i < query.length(); i++) {
      char c = query.charAt(i);

      if (state == 0) {
        if (c == '-') {
          current.append(c);
          if (query.charAt(++i) == '\"') {
            state = 2;
          } else {
            i--;
            state = 1;
          }

        } else if (c == '\"') {
          state = 2;
        } else {
          i--;
          state = 1;
        }
      } else if (state == 1) {
        if (Character.isSpaceChar(c)) {
          queries.add(current.toString());
          current = new StringBuilder();
          state = 10;

        } else {
          current.append(c);
        }
      } else if (state == 2) {
        if (c == '\"') {
          queries.add(current.toString());
          current = new StringBuilder();
          state = 10;
        } else {
          current.append(c);
        }
      } else if (state == 10) {
        if (!Character.isSpaceChar(c)) {
          i--;
          state = 0;
        }
      }
    }

    if (current.length() > 0) {
      queries.add(current.toString());
    }

    return queries;
  }
Beispiel #4
0
 /** Tests whether this condition matches the given element. */
 public boolean match(Element e, String pseudoE) {
   if (!(e instanceof CSSStylableElement)) return false; // Can't match an unstylable element.
   String attr = ((CSSStylableElement) e).getCSSClass();
   String val = getValue();
   int i = attr.indexOf(val);
   if (i == -1) {
     return false;
   }
   if (i != 0 && !Character.isSpaceChar(attr.charAt(i - 1))) {
     return false;
   }
   int j = i + val.length();
   return (j == attr.length() || (j < attr.length() && Character.isSpaceChar(attr.charAt(j))));
 }
Beispiel #5
0
    @Override
    public void keyPressed(KeyEvent e) {
      char c = e.character;
      if (Character.isLetter(c) || Character.isDigit(c) || Character.isSpaceChar(c)) {
        String filter = searchAction.getText().toLowerCase();
        if (!searching) {
          filter = "";
          searching = true;
        }

        filter += new Character(c);
        searchAction.setText(filter.toLowerCase());
        viewer.refresh(true);
      } else if (e.keyCode == SWT.BS) {
        if (searching) {
          String filter = searchAction.getText().toLowerCase();
          searchAction.setText(filter.substring(0, filter.length() - 1));
          viewer.refresh(true);
        }
      } else if (e.keyCode == SWT.ESC) {
        searching = false;
        searchAction.setText(SEARCH_LABEL);
        viewer.refresh(true);
      }
    }
Beispiel #6
0
  /**
   * Adds one phrase to the list of phrases recognised by this gazetteer
   *
   * @param text the phrase to be added
   * @param lookup the description of the annotation to be added when this phrase is recognised
   */
  public void addLookup(String text, Lookup lookup) {
    char currentChar;
    FSMState currentState = initialState;
    FSMState nextState;
    Lookup oldLookup;
    boolean isSpace;

    for (int i = 0; i < text.length(); i++) {
      currentChar = text.charAt(i);
      isSpace = Character.isSpaceChar(currentChar) || Character.isWhitespace(currentChar);
      if (isSpace) currentChar = ' ';
      else
        currentChar =
            (caseSensitive.booleanValue()) ? currentChar : Character.toUpperCase(currentChar);
      nextState = currentState.next(currentChar);
      if (nextState == null) {
        nextState = new FSMState(this);
        currentState.put(currentChar, nextState);
        if (isSpace) nextState.put(' ', nextState);
      }
      currentState = nextState;
    } // for(int i = 0; i< text.length(); i++)

    currentState.addLookup(lookup);
    // Out.println(text + "|" + lookup.majorType + "|" + lookup.minorType);

  } // addLookup
 public static void removeSpaces(ShortTermMemoryReader reader) throws IOException {
   char c = (char) reader.read();
   while (Character.isSpaceChar(c)) {
     c = (char) reader.read();
   }
   back(c, reader);
 }
 /**
  * Simple implementation
  *
  * @param s text
  * @return true/false
  */
 static boolean isDouble(final String s) {
   if (s == null) {
     return false;
   }
   final int len = s.length();
   if (len == 0) {
     return false;
   }
   boolean cond = true;
   for (int i = 0; i < len; i++) {
     final Character c = s.charAt(i);
     if (c == '-') {
       continue;
     }
     if (c == '.') {
       continue;
     }
     if (Character.isDigit(c)) {
       continue;
     }
     if (Character.isSpaceChar(c)) {
       continue;
     }
     cond = false;
     break;
   }
   return cond;
 }
Beispiel #9
0
 public static final int skipWhiteSpace(char[] data, int offset, int end) {
   int i;
   for (i = offset; i < end; i++) {
     if (!Character.isSpaceChar(data[i])) return i;
   }
   return i;
 }
  public StringBuffer translate() {
    for (index = 0; index < line.length(); index++) {
      char c = line.charAt(index);

      if (Character.isDigit(c)) {
        dealWithOperand();
      } else if (isOperator(c)) {
        dealWithOperator(c);
      } else if (c == '(') {
        stack.push(new Character(c));
      } else if (c == ')') {
        dealWithCloser();
      } else if (Character.isSpaceChar(c)) {
        // do nothing
      } else {
        System.out.println("Error: unknown character" + c);
      }
    }

    // pop and output all the operators left on the stack
    while (!stack.empty()) {
      out.append(popChar());
    }
    return out;
  }
Beispiel #11
0
 /**
  * Indicates if this sequence exists at the given index and returns the ending index.
  *
  * @param buffer is the buffer
  * @param posBegin is the beginning index
  * @param posEnd is the ending index
  * @return true if the tag matches at the given index
  */
 private Integer matchesEnd(final StringBuffer buffer, int posBegin, int posEnd) {
   Integer e;
   if (tokens.length == 1) {
     e = Integer.valueOf(posBegin + tokens[0].length());
   } else {
     e = null;
   }
   int i = posBegin + tokens[0].length();
   for (int j = 1; e == null && j < tokens.length; j++) {
     while (i < posEnd && Character.isSpaceChar(buffer.charAt(i))) {
       i++;
     }
     if (tokens[j].length() > 0
         && (i + tokens[j].length() <= posEnd)
         && matches(buffer, tokens[j], i)) {
       i += tokens[j].length();
       if (j + 1 == tokens.length) {
         e = Integer.valueOf(i);
         break;
       }
     } else {
       break;
     }
   }
   return e;
 }
Beispiel #12
0
  private List<String> getAllSubwords(String line) {
    final ArrayList<String> subwords = new ArrayList<>();
    for (int i = 0; i < line.length(); i++) {
      final char character = line.charAt(i);

      if (Character.isUpperCase(character) || Character.isDigit(character)) {
        if (mWordSinceLastCapitalBuilder.length() > 1) {
          subwords.add(mWordSinceLastCapitalBuilder.toString().toLowerCase());
        }
        mWordSinceLastCapitalBuilder.setLength(0);
      }
      if (Character.isSpaceChar(character)) {
        subwords.add(mWordSinceLastSpaceBuilder.toString().toLowerCase());
        if (mWordSinceLastCapitalBuilder.length() > 1
            && mWordSinceLastCapitalBuilder.length() != mWordSinceLastSpaceBuilder.length()) {
          subwords.add(mWordSinceLastCapitalBuilder.toString().toLowerCase());
        }
        mWordSinceLastCapitalBuilder.setLength(0);
        mWordSinceLastSpaceBuilder.setLength(0);
      } else {
        mWordSinceLastCapitalBuilder.append(character);
        mWordSinceLastSpaceBuilder.append(character);
      }
    }
    if (mWordSinceLastSpaceBuilder.length() > 0) {
      subwords.add(mWordSinceLastSpaceBuilder.toString().toLowerCase());
    }
    if (mWordSinceLastCapitalBuilder.length() > 1
        && mWordSinceLastCapitalBuilder.length() != mWordSinceLastSpaceBuilder.length()) {
      subwords.add(mWordSinceLastCapitalBuilder.toString().toLowerCase());
    }
    mWordSinceLastSpaceBuilder.setLength(0);
    mWordSinceLastCapitalBuilder.setLength(0);
    return subwords;
  }
Beispiel #13
0
  public static void main(String[] args) throws Exception {
    int size = Util.getPropertyInt("size", 100);
    double min = Util.getPropertyDouble("min", 0.01);
    double max = Util.getPropertyDouble("max", 0.9);
    Font font = new Font("serif", Font.PLAIN, size);
    String fpath = Util.getProperty("font", null);
    if (fpath != null) {
      font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(fpath));
    }

    for (char c = Character.MIN_VALUE + 1; c < Character.MAX_VALUE; ++c) {
      int type = Character.getType(c);
      if (type != Character.CONTROL
          && type != Character.FORMAT
          && type != Character.PRIVATE_USE
          && type != Character.SURROGATE
          && type != Character.UNASSIGNED
          && !Character.isMirrored(c)
          && !Character.isSpaceChar(c)) {
        String s = "" + c;
        if (Normalizer.normalize(s, NFKC).contains("\u0308")) continue; // TODO: adhoc
        UnigramMetrics m = new UnigramMetrics(s, size, false, true, font);
        if (min < m.getBlackness() && m.getBlackness() < max) {
          System.out.println("" + c + " " + (int) c);
        }
      }
    }
  }
Beispiel #14
0
 private static String nows(final String value) {
   final StringBuilder b = new StringBuilder();
   for (int i = 0; i < value.length(); i++) {
     if (!Character.isSpaceChar(value.charAt(i))) b.append(value.charAt(i));
   }
   return b.toString();
 }
Beispiel #15
0
  /**
   * This is the write() method of the stream. All Writer subclasses implement this. All other
   * versions of write() are variants of this one
   */
  public void write(char[] buffer, int index, int len) {
    synchronized (this.lock) {
      // Loop through all the characters passed to us
      for (int i = index; i < index + len; i++) {
        // If we haven't begun a page (or a new page), do that now.
        if (page == null) newpage();

        // If the character is a line terminator, then begin new line,
        // unless it is a \n immediately after a \r.
        if (buffer[i] == '\n') {
          if (!last_char_was_return) newline();
          continue;
        }
        if (buffer[i] == '\r') {
          newline();
          last_char_was_return = true;
          continue;
        } else last_char_was_return = false;

        // If it some other non-printing character, ignore it.
        if (Character.isWhitespace(buffer[i])
            && !Character.isSpaceChar(buffer[i])
            && (buffer[i] != '\t')) continue;

        // If no more characters will fit on the line, start a new line.
        if (charnum >= chars_per_line) {
          newline();
          if (page == null) newpage(); // and start a new page, if necessary
        }

        // Now print the character:
        // If it is a space, skip one space, without output.
        // If it is a tab, skip the necessary number of spaces.
        // Otherwise, print the character.
        // It is inefficient to draw only one character at a time, but
        // because our FontMetrics don't match up exactly to what the
        // printer uses we need to position each character individually.
        if (Character.isSpaceChar(buffer[i])) charnum++;
        else if (buffer[i] == '\t') charnum += 8 - (charnum % 8);
        else {
          page.drawChars(
              buffer, i, 1, x0 + charnum * charwidth, y0 + (linenum * lineheight) + lineascent);
          charnum++;
        }
      }
    }
  }
Beispiel #16
0
  static String[] getFilterSet() {
    final Collection<String> list = new ArrayList<String>();
    for (int i = 0; i < 128; i++)
      if (Character.isDigit(i) || Character.isLetter(i) || Character.isSpaceChar(i))
        list.add(String.valueOf((char) i));

    return list.toArray(new String[list.size()]);
  }
Beispiel #17
0
  /**
   * Finds the token before the one that starts at <var>startPos</var> in <var>str</var>. The token
   * will not include the whitespace surrounding it, if any.
   */
  protected void findPreviousSQLToken() {
    if (startPos == 0) {
      prevToken = "";
      prevTokenStartPos = 0;
      endBeforeToken = 0;
      return;
    }

    // Move backwards, skipping whitespace, to the end of the previous token.
    prevTokenStartPos = startPos - 1;
    while (prevTokenStartPos >= 0 && Character.isSpaceChar(str.charAt(prevTokenStartPos)))
      --prevTokenStartPos;

    int tokenEnd = prevTokenStartPos + 1;

    char c = str.charAt(prevTokenStartPos);
    boolean prevWordIsAlpha = (Character.isLetterOrDigit(c) || c == '_');

    // Continue moving backwards, stopping when we get to whitespace or '}'
    // or a char that is not of the same type.
    while (prevTokenStartPos >= 0
        && !Character.isSpaceChar(c = str.charAt(prevTokenStartPos))
        && !(c == '}') // Always stop at '}'
        && (prevWordIsAlpha
            ? (Character.isLetterOrDigit(c) || c == '_')
            : !(Character.isLetterOrDigit(c) || c == '_'))) --prevTokenStartPos;
    ++prevTokenStartPos;

    // Set flag which tells us if there is a space before the previous token
    //     spaceBeforePrevToken = prevTokenStartPos > 0
    // 	&& Character.isSpaceChar(str.charAt(prevTokenStartPos - 1));

    // Find the index of the character after the token before this token.
    // That's the same as the beginning of this whitespace before this
    // token or, if none, the beginning of this token.
    if (prevTokenStartPos == 0) endBeforeToken = 0;
    else {
      endBeforeToken = prevTokenStartPos - 1;
      while (endBeforeToken >= 0 && Character.isSpaceChar(str.charAt(endBeforeToken)))
        --endBeforeToken;
      ++endBeforeToken;
    }

    // Finally, grab the token itself, sans whitespace.
    prevToken = str.substring(prevTokenStartPos, tokenEnd);
  }
 private static int handleSpaces(String line, int pos, int delta, boolean skip) {
   int len = line.length();
   while (pos >= 0 && pos < len) {
     final char c = line.charAt(pos);
     if (skip != Character.isSpaceChar(c)) break;
     pos += delta;
   }
   return pos;
 }
 void skipSpaces() {
   while (index < s.length()) {
     char c = s.charAt(index);
     if (!Character.isSpaceChar(c) && c != '\n' && c != '\r' && c != '\t') {
       return;
     } else {
       index++;
     }
   }
 }
  public LinkedList<MetricAnalysisBean> analyzeVarnaFrequency(String metricStringInSLP)
        /*
         * @param metricString will alwayts be in SLP Encoding
         */

      {
    @SuppressWarnings("unused")
    String report = "Report of Frequency of Varnas: \n";
    HashMap<Character, Integer> map = new HashMap<Character, Integer>();

    for (char varna : metricStringInSLP.toCharArray()) {

      if (map.containsKey(varna)) {
        int i = map.get(varna) + 1;
        map.put(varna, i);
        // System.out.println("Adding Varna " + varna + " for " + i + "
        // Time");
      } else {
        // System.out.println("Adding Varna " + varna + " for First
        // Time");
        map.put(varna, 1);
      }
    }

    LinkedList<MetricAnalysisBean> list = new LinkedList<MetricAnalysisBean>();
    for (char varna : map.keySet()) {
      String varnaAsString = String.valueOf(varna);

      if (Character.isSpaceChar(varna)) {
        varnaAsString = "Space";
      } else if (varna == '\n') {
        varnaAsString = "New Line Character";
      } else if (varna == 'H') {
        varnaAsString = EncodingUtil.convertSLPToDevanagari("visarga(aH)");
      } else if (varna == 'M') {
        varnaAsString = EncodingUtil.convertSLPToDevanagari("anusvAra(aM)");
      } else if (varna == '~') {
        varnaAsString = EncodingUtil.convertSLPToDevanagari("anunAsika(a~)");
      } else if (varna == '\'') {
        varnaAsString = EncodingUtil.convertSLPToDevanagari("avagraha(\')");
      } else if (varna == '3') {
        varnaAsString = EncodingUtil.convertSLPToDevanagari("pluta(3)");
      } else if (varna == '8') {
        varnaAsString = EncodingUtil.convertSLPToDevanagari("upaDAmanIya(8)");
      } else {
        varnaAsString = EncodingUtil.convertSLPToDevanagari(varnaAsString);
      }
      MetricAnalysisBean bean = new MetricAnalysisBean();
      bean.setVarna(varnaAsString);
      bean.setFrequency(map.get(varna).toString());
      list.add(bean);
    }

    return list;
  }
 public static String lastIndent(final IDocument doc, final int offset) {
   try {
     int start = offset - 1;
     while (start >= 0 && doc.getChar(start) != '\n') start--;
     int end = start;
     while (end < offset && Character.isSpaceChar(doc.getChar(end))) end++;
     return doc.get(start + 1, end - start - 1);
   } catch (final BadLocationException e) {
     GroovyPlugin.getPlugin().logException(e.getMessage(), e);
   }
   return "";
 }
 private String lastIndent(IDocument doc, int offset) {
   try {
     int start = offset - 1;
     while (start >= 0 && doc.getChar(start) != '\n') start--;
     int end = start;
     while (end < offset && Character.isSpaceChar(doc.getChar(end))) end++;
     return doc.get(start + 1, end - start - 1);
   } catch (BadLocationException e) {
     e.printStackTrace();
   }
   return "";
 }
  private void write(String s) {
    if (s.isEmpty()) {
      return;
    }

    if (Character.isSpaceChar(s.charAt(0))) {
      wantSpace();
    }

    String[] words = ws.split(s);
    for (int i = 0; i < words.length; ) {
      writeWord(words[i]);
      if (++i < words.length) {
        wantSpace();
      }
    }

    if (Character.isSpaceChar(s.charAt(s.length() - 1))) {
      wantSpace();
    }
  }
 /**
  * Adjusts string to URL: removes spaces and non-alphanumeric characters
  *
  * @param s string to adjust
  * @return adjusted string
  */
 public static String adjutsToUrl(String s) {
   String url = CmsisConstants.EMPTY_STRING;
   if (s == null) return url;
   // Replace characters
   for (int i = 0; i < s.length(); i++) {
     char ch = s.charAt(i);
     if (Character.isSpaceChar(ch)) continue; // skip space
     if (Character.isDigit(ch)) url += ch;
     else if (Character.isLetter(ch)) url += Character.toLowerCase(ch);
     else url += '_';
   }
   return url;
 }
  @Override
  public String format(String fieldEntry) {

    StringBuilder sb = new StringBuilder(fieldEntry.length());

    for (char c : fieldEntry.toCharArray()) {
      if (!Character.isWhitespace(c) || Character.isSpaceChar(c)) {
        sb.append(c);
      }
    }

    return sb.toString();
  }
Beispiel #26
0
 public String getCommentPrefix(String text, int lineStart) {
   for (int ix = lineStart; ix + 1 < text.length(); ix++) {
     char ch = text.charAt(ix);
     if (Character.isSpaceChar(ch) || ch == '\t') {
       continue;
     }
     if (ch == '/' && text.charAt(ix + 1) == '/') {
       return text.substring(lineStart, ix + 2);
     } else {
       break;
     }
   }
   return null; // Not found
 }
Beispiel #27
0
 public static void readSeparator(ShortTermMemoryReader reader, char separator)
     throws IOException {
   try {
     char c = (char) reader.read();
     while (c != separator && Character.isSpaceChar(c)) {
       c = (char) reader.read();
     }
     if (c != separator && c != (char) -1) {
       throw new Exception("Non available separator...");
     }
   } catch (Exception e) {
     throw reader.getException("ReadService Parser Error " + e.getMessage());
   }
 }
Beispiel #28
0
 private String getFilteredQueryString(CharSequence query) {
   if (query == null) {
     return null;
   }
   final StringBuilder filtered = new StringBuilder();
   for (int n = 0; n < query.length(); n++) {
     char c = query.charAt(n);
     if (!Character.isLetterOrDigit(c) && !Character.isSpaceChar(c)) {
       continue;
     }
     filtered.append(c);
   }
   return filtered.toString();
 }
Beispiel #29
0
 /**
  * Variant of {@link #isSingleLineAndSafe(String)} that can optionally allow {@link #sep_char} or
  * {@link #sep2_char}. See that method for other conditions checked here.
  *
  * @param s string to test; if null, returns false.
  * @param allowSepChars If true, string can contain {@link #sep_char} or {@link #sep2_char}
  * @return true if all characters are OK, false otherwise. Null string or 0-length string returns
  *     false.
  * @since 2.0.00
  */
 public static final boolean isSingleLineAndSafe(final String s, final boolean allowSepChars) {
   if (s == null) return false;
   if ((!allowSepChars) && ((-1 != s.indexOf(sep_char)) || (-1 != s.indexOf(sep2_char))))
     return false;
   int i = s.length();
   if (i == 0) return false;
   --i;
   for (; i >= 0; --i) {
     final char c = s.charAt(i);
     if (Character.isISOControl(c)
         || (Character.isSpaceChar(c) && (Character.getType(c) != Character.SPACE_SEPARATOR)))
       return false;
   }
   return true;
 }
Beispiel #30
0
  /**
   * Removes one phrase to the list of phrases recognised by this gazetteer
   *
   * @param text the phrase to be removed
   * @param lookup the description of the annotation associated to this phrase
   */
  public void removeLookup(String text, Lookup lookup) {
    char currentChar;
    FSMState currentState = initialState;
    FSMState nextState;
    Lookup oldLookup;

    for (int i = 0; i < text.length(); i++) {
      currentChar = text.charAt(i);
      if (Character.isSpaceChar(currentChar) || Character.isWhitespace(currentChar))
        currentChar = ' ';
      nextState = currentState.next(currentChar);
      if (nextState == null) return; // nothing to remove
      currentState = nextState;
    } // for(int i = 0; i< text.length(); i++)
    currentState.removeLookup(lookup);
  } // removeLookup