SirIntellegence commented on code in PR #6157:
URL: https://github.com/apache/netbeans/pull/6157#discussion_r1258597889
##########
java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/ShortenedStrings.java:
##########
@@ -385,19 +348,240 @@ else if (valuesField.type() instanceof ArrayType &&
}
return string;
}
+ //would return char, but exceptions are expensive and so is boxing into
+ //a Character
+ /**
+ * (Currently untested) Grab the char at the given index in the array.
+ * Returns -1 on an error
+ * @param sourceArray Backing array reference. May be a byte or char array
+ * @param index
+ * @param backing
+ * @param isLittleEndian
+ * @return
+ */
+ private static int charAt(ArrayReference sourceArray, int index,
+ Utf16State backing, boolean isLittleEndian) throws
+ InternalExceptionWrapper, ObjectCollectedExceptionWrapper,
+ VMDisconnectedExceptionWrapper{
+ if (backing == Utf16State.Chars){
+ //that was easy
+ Value v = ArrayReferenceWrapper.getValue(sourceArray, index);
+ if (!(v instanceof CharValue)){
+ return -1;
+ }
+ return ((CharValue)v).charValue();
+ }
+ if (backing == Utf16State.Latin1){
+ //that was also easy
+ Value v = ArrayReferenceWrapper.getValue(sourceArray, index);
+ if (!(v instanceof ByteValue)){
+ return -1;
+ }
+ char c = (char)((ByteValue)v).byteValue();
+ //strip off the sign value
+ c &= 0xff;
+ return c;
+ }
+ //uft16 it is
+ int hiByteShift, lowByteShift;
+ if (isLittleEndian){
+ hiByteShift = 0;
+ lowByteShift = 8;
+ }
+ else{
+ hiByteShift = 8;
+ lowByteShift = 0;
+ }
+ List<Value> vals = ArrayReferenceWrapper.getValues(sourceArray,
+ index * 2, 2);
+ Value left = vals.get(0);
+ Value right = vals.get(1);
+ if (!(left instanceof ByteValue && right instanceof ByteValue)){
+ return -1;
+ }
+ return utf16Combine(((ByteValue)left).byteValue(),
+ ((ByteValue)right).value(), hiByteShift, lowByteShift);
+ }
+ /**
+ * (Currently untested) Grab the char at the given index in the array.
+ * Returns -1 on an error
+ * @param sourceArray Backing array reference. May be a byte or char array
+ * @param index
+ * @param backing
+ * @param isLittleEndian
+ * @return
+ */
+ private static int charAt(List<Value> sourceArray, int index,
+ Utf16State backing, boolean isLittleEndian){
+ if (backing == Utf16State.Chars){
+ //that was easy
+ Value v = sourceArray.get(index);
+ if (!(v instanceof CharValue)){
+ return -1;
+ }
+ return ((CharValue)v).charValue();
+ }
+ if (backing == Utf16State.Latin1){
+ //that was also easy
+ Value v = sourceArray.get(index);
+ if (!(v instanceof ByteValue)){
+ return -1;
+ }
+ char c = (char)((ByteValue)v).byteValue();
+ //strip off the sign value
+ c &= 0xff;
+ return c;
+ }
+ //uft16 it is
+ int hiByteShift, lowByteShift;
+ if (isLittleEndian){
+ hiByteShift = 0;
+ lowByteShift = 8;
+ }
+ else{
+ hiByteShift = 8;
+ lowByteShift = 0;
+ }
+ Value left = sourceArray.get(index * 2);
+ Value right = sourceArray.get((index * 2) + 1);
+ if (!(left instanceof ByteValue && right instanceof ByteValue)){
+ return -1;
+ }
+ return utf16Combine(((ByteValue)left).byteValue(),
+ ((ByteValue)right).value(), hiByteShift, lowByteShift);
+ }
+ /**
+ * Copy the input to the destination array as if by {@link
System#arrayCopy}
+ * @param sourceArray Backing array reference. May be a byte or char array
+ * @param backing
+ * @param isLittleEndian
+ * @param start
+ * @param length
+ * @param dest
+ * @return Null on success, otherwise an error message
+ */
+ private static String copyToCharArray(ArrayReference sourceArray,
+ int srcPos, char[] dest, int destPos, int length,
+ Utf16State backing, boolean isLittleEndian) throws
+ ObjectCollectedExceptionWrapper, VMDisconnectedExceptionWrapper,
+ InternalExceptionWrapper{
+ //grab applicable values
+ int realStart = srcPos;
+ int realLength = length;
+ if (backing == Utf16State.Utf16){
+ realStart *= 2;
+ realLength *= 2;
+ }
+ List<Value> values = ArrayReferenceWrapper.getValues(sourceArray,
+ realStart, realLength);
+ //copy them
+ return copyToCharArray(values, 0, dest, destPos, length, backing,
+ isLittleEndian);
+ }
+ /**
+ * Copy the input to the destination array as if by {@link
System#arrayCopy}
+ * @param sourceArray Backing array reference. May be a byte or char array
+ * @param backing
+ * @param isLittleEndian
+ * @param start
+ * @param length
+ * @param dest
+ * @return Null on success, otherwise an error message
Review Comment:
Fair, but `getStringWithLengthControl` is not expecting an IOException
Edit: That is actually the primary reason for that. I didn't want to have to
handle an IOException in that method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists