Example #1
0
  /* Returns the numer of times substr is contained inside string.
   */
  public static SchemaTypeNumber countSubstring(SchemaString string, SchemaString substr) {
    int nResult = 0;
    for (int i = 0; i <= string.getValue().length(); ++i)
      if (string.getValue().startsWith(substr.getValue(), i)) nResult++;

    return new SchemaInt(nResult);
  }
Example #2
0
 /* Returns the index within the string of the first occurrence of the specified substring, starting at the specified index. The first character has index=1. If the substring was not found 0 is returned.
  */
 public static SchemaTypeNumber findSubstring(
     SchemaString string, SchemaString substr, SchemaTypeNumber startindex) {
   int nStart = startindex.intValue();
   if (nStart > 0)
     return new SchemaInt(string.getValue().indexOf(substr.getValue(), nStart - 1) + 1);
   else return new SchemaInt(string.getValue().indexOf(substr.getValue()) + 1);
 }
Example #3
0
 /* Removes whitespaces on the left end of the given string.
  */
 public static SchemaString leftTrim(SchemaString string) {
   String s = string.getValue();
   int nPosition = 0;
   while (nPosition < s.length() && Character.isWhitespace(s.charAt(nPosition))) {
     nPosition++;
   }
   try {
     return new SchemaString(string.getValue().substring(nPosition, string.getValue().length()));
   } catch (IndexOutOfBoundsException e) {
     return new SchemaString(string);
   }
 }
Example #4
0
 /* Returns the index within this string of the rightmost occurrence of the specified substring, starting at the specified index. The first character has index=0. If the substring was not found -1 is returned.
  */
 public static SchemaTypeNumber reversefindSubstring(
     SchemaString string, SchemaString substr, SchemaTypeNumber endindex) {
   int nLastPosition = -1;
   int nActPosition = string.getValue().indexOf(substr.getValue());
   int nEndIndex = endindex.intValue();
   if (nEndIndex < 0) nEndIndex = string.toString().length();
   while (nActPosition > -1 && nActPosition < nEndIndex) { // note: endindex is 1 based
     nLastPosition = nActPosition;
     nActPosition = string.getValue().indexOf(substr.getValue(), nActPosition + 1);
   }
   return new SchemaInt(nLastPosition + 1);
 }
Example #5
0
 /* Returns a string with the given number of characters on the left of the given string.
  */
 public static SchemaString left(SchemaString string, SchemaTypeNumber number) {
   try {
     return new SchemaString(string.getValue().substring(0, number.intValue()));
   } catch (IndexOutOfBoundsException e) {
     return new SchemaString(string);
   }
 }
Example #6
0
 /* Returns a string with the given number of characters on the right side of the given string.
  */
 public static SchemaString right(SchemaString string, SchemaTypeNumber number) {
   String s = string.getValue();
   try {
     return new SchemaString(s.substring(s.length() - number.intValue(), s.length()));
   } catch (IndexOutOfBoundsException e) {
     return new SchemaString(string);
   }
 }
Example #7
0
 /* Removes whitespaces on the right end of the given string.
  */
 public static SchemaString rightTrim(SchemaString string) {
   String s = string.getValue();
   int nPosition = s.length();
   while (nPosition > 0 && Character.isWhitespace(s.charAt(nPosition - 1))) {
     nPosition--;
   }
   try {
     return new SchemaString(s.substring(0, nPosition));
   } catch (IndexOutOfBoundsException e) {
     return new SchemaString(string);
   }
 }
Example #8
0
  /* Formats a GUID correctly to use it in databases.
   */
  public static SchemaString formatGuidString(SchemaString val) {
    String sGuid = val.toString();
    if (sGuid.length() != 32) return new SchemaString(); // input value is not correct

    String sBuffer;
    String sResult = "";
    for (int i = 0; i < 16; ++i) {
      sBuffer = sGuid.substring(i * 2, 2);
      sResult += sBuffer;

      if (i == 3 || i == 5 || i == 7 || i == 9)
        sResult += "-"; // format correctly because it is used as string.
    }
    return new SchemaString(sResult);
  }
Example #9
0
 /* Turns every first character of a word into upper-case letters.
  */
 public static SchemaString capitalize(SchemaString value) {
   String sResult = value.getValue();
   int nPos = -1;
   while (true) {
     if (nPos < sResult.length() - 1) {
       sResult =
           sResult.substring(0, nPos + 1)
               + sResult.substring(nPos + 1, nPos + 2).toUpperCase()
               + sResult.substring(nPos + 2, sResult.length());
     }
     nPos = sResult.indexOf(" ", nPos + 1);
     if (nPos < 0) break;
   }
   return new SchemaString(sResult);
 }
Example #10
0
 /* Replaces each substring of this string that matches the given oldstring with the given newstring.
  */
 public static SchemaString replace(
     SchemaString value, SchemaString oldstring, SchemaString newstring) {
   String sResult = value.getValue();
   int nPos = sResult.indexOf(oldstring.getValue());
   while (nPos >= 0) {
     sResult =
         sResult.substring(0, nPos)
             + newstring.getValue()
             + sResult.substring(nPos + oldstring.getValue().length(), sResult.length());
     nPos = sResult.indexOf(oldstring.getValue(), nPos + newstring.getValue().length());
   }
   return new SchemaString(sResult);
 }
Example #11
0
 /* Returns true if the string value is empty. Otherwise false is returned.
  */
 public static SchemaBoolean empty(SchemaString value) {
   return new SchemaBoolean(value.getValue().length() == 0);
 }
Example #12
0
 /* Tells whether or not this string matches the given regular expression.
  */
 public static SchemaBoolean matchPattern(SchemaString string, SchemaString pattern) {
   return new SchemaBoolean(string.getValue().matches(pattern.getValue()));
 }
Example #13
0
 /* Performes a string comparation ignoring the case of characters. Returns 0 if strings are equal. Returns -1 if string1 < string2. Returns +1 if string1 > string2.
  */
 public static SchemaTypeNumber stringCompareIgnoreCase(
     SchemaString string1, SchemaString string2) {
   return new SchemaInt(string1.getValue().compareToIgnoreCase(string2.getValue()));
 }
Example #14
0
 /* Returns the numeric code of the first character given by the string value.
  */
 public static SchemaTypeNumber codeFromChar(SchemaString value) {
   return new SchemaInt((int) value.getValue().charAt(0));
 }
Example #15
0
 /* Result is the lowercase version of all the characters in the string.
  */
 public static SchemaString lowercase(SchemaString string) {
   return new SchemaString(string.getValue().toLowerCase());
 }