当前位置: 首页>>代码示例>>Java>>正文


Java NativeUnsafe.charAt方法代码示例

本文整理汇总了Java中com.sun.squawk.NativeUnsafe.charAt方法的典型用法代码示例。如果您正苦于以下问题:Java NativeUnsafe.charAt方法的具体用法?Java NativeUnsafe.charAt怎么用?Java NativeUnsafe.charAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.squawk.NativeUnsafe的用法示例。


在下文中一共展示了NativeUnsafe.charAt方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: contentEquals

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
   * Compares this string to the specified {@code CharSequence}.  The result
   * is {@code true} if and only if this {@code String} represents the same
   * sequence of char values as the specified sequence.
   *
   * @param  cs
   *         The sequence to compare this {@code String} against
   *
   * @return  {@code true} if this {@code String} represents the same
   *          sequence of char values as the specified sequence, {@code
   *          false} otherwise
   *
   * @since  1.5
   */
  public boolean contentEquals(CharSequence cs) {
if (length() != cs.length()) {
	return false;
}
      if (cs instanceof String) {
	return ((String)cs).equals(this);
}
int lth = length();
for (int i = 0 ; i < lth ; i++) {		
	if (NativeUnsafe.charAt(this, i) != cs.charAt(i)) {
		return false;
	}
}
return true;
  }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:30,代码来源:String.java

示例2: equals

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
 * Compares this string to the specified object.
 * The result is <code>true</code> if and only if the argument is not
 * <code>null</code> and is a <code>String</code> object that represents
 * the same sequence of characters as this object.
 *
 * @param   anObject   the object to compare this <code>String</code>
 *                     against.
 * @return  <code>true</code> if the <code>String </code>are equal;
 *          <code>false</code> otherwise.
 * @see     java.lang.String#compareTo(java.lang.String)
 * @see     java.lang.String#equalsIgnoreCase(java.lang.String)
 */
public boolean equals(Object anObject) {
    if (this == anObject) {
        return true;
    }
    if (anObject instanceof String) {
        String anotherString = (String)anObject;
        int lth = length();
        if (lth == anotherString.length()) {
            if (isEightBit() && anotherString.isEightBit()) {
                for (int i = 0 ; i < lth ; i++) {
                	if (NativeUnsafe.getByte(this, i) != NativeUnsafe.getByte(anotherString, i)) {
                        return false;
                    }
                }
            } else {
                for (int i = 0 ; i < lth ; i++) {
                	if (NativeUnsafe.charAt(this, i) != NativeUnsafe.charAt(anotherString, i)) {
                        return false;
                    }
                }
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:40,代码来源:String.java

示例3: lastIndexOf

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
public int lastIndexOf(String str, int fromIndex) {
	int targetCount = str.length();
       int rightIndex = this.length() - targetCount;
       if (fromIndex < 0) {
           return -1;
       }
       if (fromIndex > rightIndex) {
           fromIndex = rightIndex;
       }
       /* Empty string always matches. */
       if (targetCount == 0) {
           return fromIndex;
       }

       int strLastIndex = targetCount - 1;
       char strLastChar = NativeUnsafe.charAt(str, strLastIndex);
       int min = targetCount - 1;
       int i = min + fromIndex;

   startSearchForLastChar:
       while (true) {
           while (i >= min && NativeUnsafe.charAt(this, i) != strLastChar) {
               i--;
           }
           if (i < min) {
               return -1;
           }
           int j = i - 1;
           int start = j - (targetCount - 1);
           int k = strLastIndex - 1;

           while (j > start) {
               if (NativeUnsafe.charAt(this, j--) != NativeUnsafe.charAt(str, k--)) {
                   i--;
                   continue startSearchForLastChar;
               }
           }
           return start - 1;
       }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:41,代码来源:String.java

示例4: indexOf

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
 * Returns the index within this string of the first occurrence of the
 * specified character, starting the search at the specified index.
 * <p>
 * If a character with value <code>ch</code> occurs in the character
 * sequence represented by this <code>String</code> object at an index
 * no smaller than <code>fromIndex</code>, then the index of the first
 * such occurrence is returned--that is, the smallest value <i>k</i>
 * such that:
 * <blockquote><pre>
 * (this.charAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
 * </pre></blockquote>
 * is true. If no such character occurs in this string at or after
 * position <code>fromIndex</code>, then <code>-1</code> is returned.
 * <p>
 * There is no restriction on the value of <code>fromIndex</code>. If it
 * is negative, it has the same effect as if it were zero: this entire
 * string may be searched. If it is greater than the length of this
 * string, it has the same effect as if it were equal to the length of
 * this string: <code>-1</code> is returned.
 *
 * @param   ch          a character.
 * @param   fromIndex   the index to start the search from.
 * @return  the index of the first occurrence of the character in the
 *          character sequence represented by this object that is greater
 *          than or equal to <code>fromIndex</code>, or <code>-1</code>
 *          if the character does not occur.
 */
public int indexOf(int ch, int fromIndex) {
    int max = length();

    if (fromIndex < 0) {
        fromIndex = 0;
    } else if (fromIndex >= max) {
        return -1; // Note: fromIndex might be near -1>>>1.
    }
    for (int i = fromIndex ; i < max ; i++) {
        if (NativeUnsafe.charAt(this, i) == ch) {
             return i;
        }
    }
    return -1;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:44,代码来源:String.java

示例5: indexOf

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
 * Returns the index within this string of the first occurrence of the
 * specified substring, starting at the specified index.  The integer
 * returned is the smallest value {@code k} for which:
 * <pre>{@code
 *     k >= Math.min(fromIndex, this.length()) &&
 *                   this.toString().startsWith(str, k)
 * }</pre>
 * If no such value of <i>k</i> exists, then -1 is returned.
 *
 * @param   str         the substring for which to search.
 * @param   fromIndex   the index from which to start the search.
 * @return  the index within this string of the first occurrence of the
 *          specified substring, starting at the specified index.
 */
public int indexOf(String str, int fromIndex) {
    int this_length = this.length();
    int str_length = str.length();
    int max = this_length - str_length;
    if (fromIndex >= this_length) {
        if (this_length == 0 && fromIndex == 0 && str_length == 0) {
            /* There is an empty string at index 0 in an empty string. */
            return 0;
        }
        /* Note: fromIndex might be near -1>>>1 */
        return -1;
    }
    if (fromIndex < 0) {
        fromIndex = 0;
    }
    if (str_length == 0) {
        return fromIndex;
    }

    char first    = NativeUnsafe.charAt(str, 0);
    int i = fromIndex;

startSearchForFirstChar:
    while (true) {

        /* Look for first character. */
        while (i <= max && value[i] != first) {
            i++;
        }
        if (i > max) {
            return -1;
        }

        /* Found first character, now look at the rest of v2 */
        int j   = i + 1;
        int end = j + str_length - 1;
        int k   = 1;
        while (j < end) {
            if (value[j++] != NativeUnsafe.charAt(str, k++)) {
                i++;
                /* Look for str's first char again. */
                continue startSearchForFirstChar;
            }
        }
        return i;  /* Found whole string. */
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:63,代码来源:AbstractStringBuilder.java

示例6: replace

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
 * Returns a new string resulting from replacing all occurrences of
 * <code>oldChar</code> in this string with <code>newChar</code>.
 * <p>
 * If the character <code>oldChar</code> does not occur in the
 * character sequence represented by this <code>String</code> object,
 * then a reference to this <code>String</code> object is returned.
 * Otherwise, a new <code>String</code> object is created that
 * represents a character sequence identical to the character sequence
 * represented by this <code>String</code> object, except that every
 * occurrence of <code>oldChar</code> is replaced by an occurrence
 * of <code>newChar</code>.
 * <p>
 * Examples:
 * <blockquote><pre>
 * "mesquite in your cellar".replace('e', 'o')
 *         returns "mosquito in your collar"
 * "the war of baronets".replace('r', 'y')
 *         returns "the way of bayonets"
 * "sparring with a purple porpoise".replace('p', 't')
 *         returns "starring with a turtle tortoise"
 * "JonL".replace('q', 'x') returns "JonL" (no change)
 * </pre></blockquote>
 *
 * @param   oldChar   the old character.
 * @param   newChar   the new character.
 * @return  a string derived from this string by replacing every
 *          occurrence of <code>oldChar</code> with <code>newChar</code>.
 */
public String replace(char oldChar, char newChar) {
    if (oldChar != newChar) {
        int len = length();
        int i = -1;

        while (++i < len) {
            if (NativeUnsafe.charAt(this, i) == oldChar) {
                break;
            }
        }
        if (i < len) {
            char buf[] = new char[len];
            for (int j = 0 ; j < i ; j++) {
                buf[j] = NativeUnsafe.charAt(this, j);
            }
            while (i < len) {
                char c = NativeUnsafe.charAt(this, i);
                buf[i] = (c == oldChar) ? newChar : c;
                i++;
            }
            return new String(buf, 0, len);
        }
    }
    return this;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:55,代码来源:String.java

示例7: lastIndexOf

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
   * Returns the index within this string of the last occurrence of the
   * specified substring. The integer returned is the largest value <i>k</i>
   * such that:
   * <pre>{@code
   *     k <= Math.min(fromIndex, this.length()) &&
   *                   this.toString().startsWith(str, k)
   * }</pre>
   * If no such value of <i>k</i> exists, then -1 is returned.
   *
   * @param   str         the substring to search for.
   * @param   fromIndex   the index to start the search from.
   * @return  the index within this sequence of the last occurrence of the
   *          specified substring.
   */
  public int lastIndexOf(String str, int fromIndex) {
int targetCount = str.length();
      int rightIndex = this.length() - targetCount;
      if (fromIndex < 0) {
          return -1;
      }
      if (fromIndex > rightIndex) {
          fromIndex = rightIndex;
      }
      /* Empty string always matches. */
      if (targetCount == 0) {
          return fromIndex;
      }

      int strLastIndex = targetCount - 1;
      char strLastChar = NativeUnsafe.charAt(str, strLastIndex);
      int min = targetCount - 1;
      int i = min + fromIndex;

  startSearchForLastChar:
      while (true) {
          while (i >= min && value[i] != strLastChar) {
              i--;
          }
          if (i < min) {
              return -1;
          }
          int j = i - 1;
          int start = j - (targetCount - 1);
          int k = strLastIndex - 1;

          while (j > start) {
              if (value[j--] != NativeUnsafe.charAt(str, k--)) {
                  i--;
                  continue startSearchForLastChar;
              }
          }
          return start + 1;
      }
  }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:56,代码来源:AbstractStringBuilder.java

示例8: startsWith

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
 * Tests if this string starts with the specified prefix beginning
 * at the specified index.
 *
 * @param   prefix    the prefix.
 * @param   toffset   where to begin looking in the string.
 * @return  <code>true</code> if the character sequence represented by the
 *          argument is a prefix of the substring of this object starting
 *          at index <code>toffset</code>; <code>false</code> otherwise.
 *          The result is <code>false</code> if <code>toffset</code> is
 *          negative or greater than the length of this
 *          <code>String</code> object; otherwise the result is the same
 *          as the result of the expression
 *          <pre>
 *          this.subString(toffset).startsWith(prefix)
 *          </pre>
 * @exception java.lang.NullPointerException if <code>prefix</code> is
 *          <code>null</code>.
 */
public boolean startsWith(String prefix, int toffset) {
    int to   = toffset;
    int plth = prefix.length();
    /*
     * Note: toffset might be near -1>>>1.
     */
    if ((toffset < 0) || (toffset > length() - plth)) {
        return false;
    }
    for (int i = 0 ; i < plth ; i++) {
        if (NativeUnsafe.charAt(this, to+i) != NativeUnsafe.charAt(prefix, i)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:36,代码来源:String.java

示例9: charAt

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
 * Returns the character at the specified index. An index ranges
 * from <code>0</code> to <code>length() - 1</code>. The first character
 * of the sequence is at index <code>0</code>, the next at index
 * <code>1</code>, and so on, as for array indexing.
 *
 * @param      index   the index of the character.
 * @return     the character at the specified index of this string.
 *             The first character is at index <code>0</code>.
 * @exception  IndexOutOfBoundsException  if the <code>index</code>
 *             argument is negative or not less than the length of this
 *             string.
 */
public char charAt(int index) {
    if ((index < 0) || (index >= length())) {
        throw new StringIndexOutOfBoundsException(index);
    }
    return NativeUnsafe.charAt(this, index);
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:20,代码来源:String.java

示例10: compareTo

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
 * Compares two strings lexicographically.
 * The comparison is based on the Unicode value of each character in
 * the strings. The character sequence represented by this
 * <code>String</code> object is compared lexicographically to the
 * character sequence represented by the argument string. The result is
 * a negative integer if this <code>String</code> object
 * lexicographically precedes the argument string. The result is a
 * positive integer if this <code>String</code> object lexicographically
 * follows the argument string. The result is zero if the strings
 * are equal; <code>compareTo</code> returns <code>0</code> exactly when
 * the {@link #equals(Object)} method would return <code>true</code>.
 * <p>
 * This is the definition of lexicographic ordering. If two strings are
 * different, then either they have different characters at some index
 * that is a valid index for both strings, or their lengths are different,
 * or both. If they have different characters at one or more index
 * positions, let <i>k</i> be the smallest such index; then the string
 * whose character at position <i>k</i> has the smaller value, as
 * determined by using the < operator, lexicographically precedes the
 * other string. In this case, <code>compareTo</code> returns the
 * difference of the two character values at position <i>k</i> in
 * the two string -- that is, the value:
 * <blockquote><pre>
 * this.charAt(k)-anotherString.charAt(k)
 * </pre></blockquote>
 * If there is no index position at which they differ, then the shorter
 * string lexicographically precedes the longer string. In this case,
 * <code>compareTo</code> returns the difference of the lengths of the
 * strings -- that is, the value:
 * <blockquote><pre>
 * this.length()-anotherString.length()
 * </pre></blockquote>
 *
 * @param   anotherString   the <code>String</code> to be compared.
 * @return  the value <code>0</code> if the argument string is equal to
 *          this string; a value less than <code>0</code> if this string
 *          is lexicographically less than the string argument; and a
 *          value greater than <code>0</code> if this string is
 *          lexicographically greater than the string argument.
 * @exception java.lang.NullPointerException if <code>anotherString</code>
 *          is <code>null</code>.
 */
public int compareTo(String anotherString) {
    int len1 = length();
    int len2 = anotherString.length();
    int lth = len1 < len2 ? len1 : len2;
    for (int i = 0 ; i < lth ; i++) {
        char c1 = NativeUnsafe.charAt(this, i);
        char c2 = NativeUnsafe.charAt(anotherString, i);
        if (c1 != c2) {
            return c1 - c2;
        }
    }
    return len1 - len2;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:57,代码来源:String.java

示例11: lastIndexOf

import com.sun.squawk.NativeUnsafe; //导入方法依赖的package包/类
/**
 * Returns the index within this string of the last occurrence of the
 * specified character, searching backward starting at the specified
 * index. That is, the index returned is the largest value <i>k</i>
 * such that:
 * <blockquote><pre>
 * (this.charAt(k) == ch) && (k <= fromIndex)
 * </pre></blockquote>
 * is true.
 *
 * @param   ch          a character.
 * @param   fromIndex   the index to start the search from. There is no
 *          restriction on the value of <code>fromIndex</code>. If it is
 *          greater than or equal to the length of this string, it has
 *          the same effect as if it were equal to one less than the
 *          length of this string: this entire string may be searched.
 *          If it is negative, it has the same effect as if it were -1:
 *          -1 is returned.
 * @return  the index of the last occurrence of the character in the
 *          character sequence represented by this object that is less
 *          than or equal to <code>fromIndex</code>, or <code>-1</code>
 *          if the character does not occur before that point.
 */
public int lastIndexOf(int ch, int fromIndex) {
    int len = length();
    for (int i = ((fromIndex >= len) ? len - 1 : fromIndex) ; i >= 0 ; i--) {
        if (NativeUnsafe.charAt(this, i) == ch) {
            return i;
        }
    }
    return -1;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:33,代码来源:String.java


注:本文中的com.sun.squawk.NativeUnsafe.charAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。