Пример #1
0
 /**
  * ** Returns true if the specified character is a valid character to use in ** an ID ** @param ch
  * The character ** @return True if the specified character is a valid character to use in ** an
  * ID
  */
 public static boolean isValidIDChar(char ch) {
   // At a minimum, avoid the following special chars:
   //   $   - substitution character
   //   {}  - have had problems using this character in MySQL
   //   %   - MySQL wildcard character
   //   *   - generic wildcard character
   //   \   - escape character
   //   ?   - just don't use it
   //   ,   - will get confused as a field separator
   //   |   - will get confused as a field separator
   //   /   - will get confused as a field separator
   //   =   - will get confused as a key=value separator
   //   "'` - quotation characters
   //   #   - possible beginning of comment
   //   ~   - just don't use it
   //   ?   - just don't use it
   //   ^   - just don't use it
   // Pending possibles:
   //   !   - Looks like '|'?
   //   -   - ?
   //   +   - ?
   // @abc,#abc,_abc,.abc,&abc
   if (Character.isLetterOrDigit(ch)) {
     return true;
   } else if ((ch == '.') || (ch == '_')) {
     // definately accept these
     return true;
   } else if ((ch == '@') || (ch == '&') || (ch == '-')) {
     // we'll consider these
     return true;
   } else {
     return false;
   }
 }
Пример #2
0
 /** Receive notification of character data inside an element. */
 @Override
 public void characters(char ch[], int start, int len) {
   while (len > 0 && Character.isWhitespace(ch[start])) {
     ++start;
     --len;
   }
   while (len > 0 && Character.isWhitespace(ch[start + len - 1])) {
     --len;
   }
   if (len > 0) {
     if (_chars.length() > 0) {
       _chars.append(' ');
     }
     _chars.append(ch, start, len);
   }
 }
Пример #3
0
 /**
  * ** Filters an ID String, convertering all letters to lowercase and ** removing invalid
  * characters ** @param text The ID String to filter ** @return The filtered ID String
  */
 public static String FilterID(String text) {
   // ie. "sky.12", "acme@123"
   if (text != null) {
     StringBuffer sb = new StringBuffer();
     for (int i = 0; i < text.length(); i++) {
       char ch = Character.toLowerCase(text.charAt(i));
       if (DBRecordKey.isValidIDChar(ch)) {
         sb.append(ch);
       }
     }
     return sb.toString();
   } else {
     return "";
   }
 }
Пример #4
0
 private static String FilterID(String id) {
   if (id == null) {
     return null;
   } else {
     StringBuffer newID = new StringBuffer();
     int st = 0;
     for (int i = 0; i < id.length(); i++) {
       char ch = Character.toLowerCase(id.charAt(i));
       if (Character.isLetterOrDigit(ch)) {
         newID.append(ch);
         st = 1;
       } else if (st == 1) {
         newID.append("_");
         st = 0;
       } else {
         // ignore char
       }
     }
     while ((newID.length() > 0) && (newID.charAt(newID.length() - 1) == '_')) {
       newID.setLength(newID.length() - 1);
     }
     return newID.toString();
   }
 }
Пример #5
0
  /**
   * Returns true if two names match without regard to case or the presence of '-' or '_'
   * characters.
   *
   * @param beanName The name of the bean property to compare
   * @param elementName The name of the element to compare
   * @return True if the names match
   */
  public static boolean namesMatch(String beanName, String elementName) {
    int beanNameLen = beanName.length();
    int elementNameLen = elementName.length();

    int elementPos = 0;
    int beanPos = 0;

    // Keep looping until you hit the end of either of the strings
    while ((elementPos < elementNameLen) && (beanPos < beanNameLen)) {
      // If the next character in the bean name is a '-' or a '/', skip it
      char beanCh = Character.toLowerCase(beanName.charAt(beanPos));
      if ((beanCh == '-') || (beanCh == '_')) {
        beanPos++;
        continue;
      }

      // If the next character in the element name is a '-' or a '/', skip it
      char elementCh = Character.toLowerCase(elementName.charAt(elementPos));
      if ((elementCh == '-') || (elementCh == '_')) {
        elementPos++;
        continue;
      }

      // If the characters don't match, the names don't match
      if (elementCh != beanCh) return false;
      elementPos++;
      beanPos++;
    }

    // You hit the end of both names at the same time, the names match
    if ((elementPos == elementNameLen) && (beanPos == beanNameLen)) {
      return true;
    }

    return false;
  }
Пример #6
0
  private String modifyCharacter(Character baseChar, Character modifierChar) {
    String result = null;

    switch (classifyChar(modifierChar)) {
      case DIAERESIS:
        result = addDiaeresisToCharV1(baseChar);
        break;
      case ACUTE_ACCENT:
        result = addAcuteAccentToChar(baseChar);
        break;
      case GRAVE_ACCENT:
        result = addGraveAccentToChar(baseChar);
        break;
      case CIRCUMFLEX:
        result = addCircumflexAccentToChar(baseChar);
        break;
      case TILDE:
        result = addTildeToChar(baseChar);
        break;
      case NORDIC_RING:
        result = addNordicRingToChar(baseChar);
        break;
      case CZECH_CARON:
        result = addCzechCaronToChar(baseChar);
        break;
      case CEDILLA:
        result = addCedillaToChar(baseChar);
        break;
      case NOT_A_MODIFIER:
        result = baseChar.toString();
        break;
      default:
        break;
    }

    if (result == null) {
      LOGGER.debug(
          "FIXME: cannot apply modifier '" + modifierChar + "' to character '" + baseChar + "'");
    }

    return result;
  }
Пример #7
0
 private static short[] load(String name, Reader input, Model.Translator translator)
     throws java.io.IOException {
   short[] sequence = null;
   char[] buffer = new char[10240];
   int len;
   while ((len = input.read(buffer)) > 0) {
     for (int i = len - 1; i >= 0; i--) {
       if (Character.isWhitespace(buffer[i])) {
         if (i == (len - 1)) {
           len--;
         } else {
           System.arraycopy(buffer, i + 1, buffer, i, len - i - 1);
         }
       }
     }
     int start;
     if (sequence == null) {
       sequence = new short[len];
       start = 0;
     } else {
       start = sequence.length;
       short[] newseq = new short[sequence.length + len];
       System.arraycopy(sequence, 0, newseq, 0, sequence.length);
       sequence = newseq;
     }
     for (int i = 0; i < len; i++) {
       sequence[start + i] = translator.translate(buffer[i]);
       if (sequence[start + i] < 0) {
         throw new IOException(
             "Sequence character '"
                 + buffer[i]
                 + "' ("
                 + ((int) buffer[i])
                 + ") at offset "
                 + (start + i)
                 + " is not in the model's lexicon.");
       }
     }
   }
   return sequence;
 }
Пример #8
0
 /**
  * Get any children that match this name or path. Similar to getChild(), but will grab multiple
  * matches rather than only the first.
  *
  * @param name element name or path/to/element
  * @return array of child elements that match
  * @author processing.org
  */
 public XML[] getChildren(String name) {
   if (name.length() > 0 && name.charAt(0) == '/') {
     throw new IllegalArgumentException("getChildren() should not begin with a slash");
   }
   if (name.indexOf('/') != -1) {
     return getChildrenRecursive(PApplet.split(name, '/'), 0);
   }
   // if it's a number, do an index instead
   // (returns a single element array, since this will be a single match
   if (Character.isDigit(name.charAt(0))) {
     return new XML[] {getChild(Integer.parseInt(name))};
   }
   int childCount = getChildCount();
   XML[] matches = new XML[childCount];
   int matchCount = 0;
   for (int i = 0; i < childCount; i++) {
     XML kid = getChild(i);
     String kidName = kid.getName();
     if (kidName != null && kidName.equals(name)) {
       matches[matchCount++] = kid;
     }
   }
   return (XML[]) PApplet.subset(matches, 0, matchCount);
 }
Пример #9
0
 /**
  * Internal helper function for getChild(String).
  *
  * @param items result of splitting the query on slashes
  * @param offset where in the items[] array we're currently looking
  * @return matching element or null if no match
  * @author processing.org
  */
 protected XML getChildRecursive(String[] items, int offset) {
   // if it's a number, do an index instead
   if (Character.isDigit(items[offset].charAt(0))) {
     XML kid = getChild(Integer.parseInt(items[offset]));
     if (offset == items.length - 1) {
       return kid;
     } else {
       return kid.getChildRecursive(items, offset + 1);
     }
   }
   int childCount = getChildCount();
   for (int i = 0; i < childCount; i++) {
     XML kid = getChild(i);
     String kidName = kid.getName();
     if (kidName != null && kidName.equals(items[offset])) {
       if (offset == items.length - 1) {
         return kid;
       } else {
         return kid.getChildRecursive(items, offset + 1);
       }
     }
   }
   return null;
 }