Fix for Issue 153: Asterix build fails on Mac
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization@549 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/utils/UTF8CharSequence.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/utils/UTF8CharSequence.java
index a6d1c54..a3ebbbd 100644
--- a/asterix-common/src/main/java/edu/uci/ics/asterix/common/utils/UTF8CharSequence.java
+++ b/asterix-common/src/main/java/edu/uci/ics/asterix/common/utils/UTF8CharSequence.java
@@ -5,58 +5,73 @@
public class UTF8CharSequence implements CharSequence {
- private int start;
- private int len;
- private char[] buf;
+ private int start;
+ private int len;
+ private char[] buf;
- public UTF8CharSequence(IValueReference valueRef, int start) {
- reset(valueRef, start);
- }
+ public UTF8CharSequence(IValueReference valueRef, int start) {
+ reset(valueRef, start);
+ }
- public UTF8CharSequence() {
- }
+ public UTF8CharSequence() {
+ }
- @Override
- public char charAt(int index) {
- if (index >= len || index < 0) {
- throw new IndexOutOfBoundsException("No index " + index + " for string of length " + len);
- }
- return buf[index];
- }
+ @Override
+ public char charAt(int index) {
+ if (index >= len || index < 0) {
+ throw new IndexOutOfBoundsException("No index " + index
+ + " for string of length " + len);
+ }
+ return buf[index];
+ }
- @Override
- public int length() {
- return len;
- }
+ @Override
+ public int length() {
+ return len;
+ }
- @Override
- public CharSequence subSequence(int start, int end) {
- UTF8CharSequence carSeq = new UTF8CharSequence();
- carSeq.len = end - start + 1;
- carSeq.buf = new char[carSeq.len];
- System.arraycopy(buf, start, carSeq.buf, 0, carSeq.len);
- return carSeq;
- }
+ @Override
+ public CharSequence subSequence(int start, int end) {
+ UTF8CharSequence carSeq = new UTF8CharSequence();
+ carSeq.len = end - start;
+ if (end != start) {
+ carSeq.buf = new char[carSeq.len];
+ System.arraycopy(buf, start, carSeq.buf, 0, carSeq.len);
+ }
+ return carSeq;
+ }
- public void reset(IValueReference valueRef, int start) {
- this.start = start;
- resetLength(valueRef);
- if (buf == null || buf.length < len) {
- buf = new char[len];
- }
- int sStart = start + 2;
- int c = 0;
- int i = 0;
- byte[] bytes = valueRef.getByteArray();
- while (c < len) {
- buf[i++] = UTF8StringPointable.charAt(bytes, sStart + c);
- c += UTF8StringPointable.charSize(bytes, sStart + c);
- }
+ public void reset(IValueReference valueRef, int start) {
+ this.start = start;
+ resetLength(valueRef);
+ if (buf == null || buf.length < len) {
+ buf = new char[len];
+ }
+ int sStart = start + 2;
+ int c = 0;
+ int i = 0;
+ byte[] bytes = valueRef.getByteArray();
+ while (c < len) {
+ buf[i++] = UTF8StringPointable.charAt(bytes, sStart + c);
+ c += UTF8StringPointable.charSize(bytes, sStart + c);
+ }
- }
+ }
- private void resetLength(IValueReference valueRef) {
- this.len = UTF8StringPointable.getUTFLength(valueRef.getByteArray(), start);
- }
+ private void resetLength(IValueReference valueRef) {
+ this.len = UTF8StringPointable.getUTFLength(valueRef.getByteArray(),
+ start);
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer bf = new StringBuffer();
+ if (buf != null) {
+ for (int i = 0; i < buf.length; i++) {
+ bf.append(buf[i]);
+ }
+ }
+ return new String(bf);
+ }
}