incubator-vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject svn commit: r1390769 - /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointsToStringEvaluatorFactory.java
Date Wed, 26 Sep 2012 23:05:18 GMT
Author: prestonc
Date: Wed Sep 26 23:05:17 2012
New Revision: 1390769

URL: http://svn.apache.org/viewvc?rev=1390769&view=rev
Log:
Added support for single integer argument. Also a check for if the code point is defined.

Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointsToStringEvaluatorFactory.java

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointsToStringEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointsToStringEvaluatorFactory.java?rev=1390769&r1=1390768&r2=1390769&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointsToStringEvaluatorFactory.java
(original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointsToStringEvaluatorFactory.java
Wed Sep 26 23:05:17 2012
@@ -26,6 +26,7 @@ import org.apache.vxquery.exceptions.Err
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
+import org.apache.vxquery.runtime.functions.util.FunctionHelper;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
@@ -56,12 +57,6 @@ public class FnCodepointsToStringEvaluat
             @Override
             protected void evaluate(TaggedValuePointable[] args, IPointable result) throws
SystemException {
                 TaggedValuePointable tvp1 = args[0];
-                // Only accept sequences as input.
-                if (tvp1.getTag() != ValueTag.SEQUENCE_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(seqp);
-
                 try {
                     // Byte Format: Type (1 byte) + String Length (2 bytes) + String.
                     DataOutput out = abvs.getDataOutput();
@@ -71,22 +66,26 @@ public class FnCodepointsToStringEvaluat
                     out.write(0);
                     out.write(0);
 
-                    int c;
-                    for (int j = 0; j < seqp.getEntryCount(); ++j) {
-                        seqp.getEntry(j, p);
-                        tvp.set(p.getByteArray(), p.getStartOffset(), p.getLength());
-                        tvp.getValue(longp);
-                        c = longp.intValue();
-                        if ((c >= 0x0001) && (c <= 0x007F)) {
-                            out.write((byte) c);
-                        } else if (c > 0x07FF) {
-                            out.write((byte) (0xE0 | ((c >> 12) & 0x0F)));
-                            out.write((byte) (0x80 | ((c >> 6) & 0x3F)));
-                            out.write((byte) (0x80 | ((c >> 0) & 0x3F)));
-                        } else {
-                            out.write((byte) (0xC0 | ((c >> 6) & 0x1F)));
-                            out.write((byte) (0x80 | ((c >> 0) & 0x3F)));
+                    // Only accept sequences of integers or an integer as input.
+                    if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                        tvp1.getValue(seqp);
+                        for (int j = 0; j < seqp.getEntryCount(); ++j) {
+                            seqp.getEntry(j, p);
+                            tvp.set(p.getByteArray(), p.getStartOffset(), p.getLength());
+                            tvp.getValue(longp);
+                            if (!Character.isDefined(longp.intValue())) {
+                                throw new SystemException(ErrorCode.FOCH0001);
+                            }
+                            FunctionHelper.writeChar((char) longp.intValue(), out);
+                        }
+                    } else if (tvp1.getTag() == ValueTag.XS_INTEGER_TAG) {
+                        tvp1.getValue(longp);
+                        if (!Character.isDefined(longp.intValue())) {
+                            throw new SystemException(ErrorCode.FOCH0001);
                         }
+                        FunctionHelper.writeChar((char) longp.intValue(), out);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
                     }
 
                     // Update the full length string in the byte array.



Mime
View raw message