本文整理匯總了Java中gov.nasa.jpf.vm.CharArrayFields.asCharArray方法的典型用法代碼示例。如果您正苦於以下問題:Java CharArrayFields.asCharArray方法的具體用法?Java CharArrayFields.asCharArray怎麽用?Java CharArrayFields.asCharArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gov.nasa.jpf.vm.CharArrayFields
的用法示例。
在下文中一共展示了CharArrayFields.asCharArray方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: concat__Ljava_lang_String_2__Ljava_lang_String_2
import gov.nasa.jpf.vm.CharArrayFields; //導入方法依賴的package包/類
@MJI
public int concat__Ljava_lang_String_2__Ljava_lang_String_2 (MJIEnv env, int objRef, int strRef) {
Heap heap = env.getHeap();
ElementInfo thisStr = heap.get(objRef);
CharArrayFields thisFields = (CharArrayFields) heap.get(thisStr.getReferenceField("value")).getFields();
char[] thisChars = thisFields.asCharArray();
int thisLength = thisChars.length;
ElementInfo otherStr = heap.get(strRef);
CharArrayFields otherFields = (CharArrayFields) heap.get(otherStr.getReferenceField("value")).getFields();
char[] otherChars = otherFields.asCharArray();
int otherLength = otherChars.length;
if (otherLength == 0) { return objRef; }
char resultChars[] = new char[thisLength + otherLength];
System.arraycopy(thisChars, 0, resultChars, 0, thisLength);
System.arraycopy(otherChars, 0, resultChars, thisLength, otherLength);
return env.newString(new String(resultChars));
}
示例2: trim____Ljava_lang_String_2
import gov.nasa.jpf.vm.CharArrayFields; //導入方法依賴的package包/類
@MJI
public int trim____Ljava_lang_String_2 (MJIEnv env, int objRef) {
Heap heap = env.getHeap();
ElementInfo thisStr = heap.get(objRef);
CharArrayFields thisFields = (CharArrayFields) heap.get(thisStr.getReferenceField("value")).getFields();
char[] thisChars = thisFields.asCharArray();
int thisLength = thisChars.length;
int start = 0;
int end = thisLength;
while ((start < end) && (thisChars[start] <= ' ')) {
start++;
}
while ((start < end) && (thisChars[end - 1] <= ' ')) {
end--;
}
if (start == 0 && end == thisLength) {
// if there was no white space, return the string itself
return objRef;
}
String result = new String(thisChars, start, end - start);
return env.newString(result);
}