aboutsummaryrefslogtreecommitdiff
path: root/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java')
-rw-r--r--src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java73
1 files changed, 39 insertions, 34 deletions
diff --git a/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java b/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
index 74acd2a..dc3a3ce 100644
--- a/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -24,39 +24,36 @@
package com.sun.org.apache.xalan.internal.xsltc.runtime;
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.FieldPosition;
-import java.text.MessageFormat;
-import java.text.NumberFormat;
-import java.util.Locale;
-import java.util.ResourceBundle;
-import javax.xml.transform.dom.DOMSource;
-
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.Translet;
import com.sun.org.apache.xalan.internal.xsltc.dom.AbsoluteIterator;
-import com.sun.org.apache.xml.internal.dtm.Axis;
+import com.sun.org.apache.xalan.internal.xsltc.dom.ArrayNodeListIterator;
import com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter;
import com.sun.org.apache.xalan.internal.xsltc.dom.MultiDOM;
import com.sun.org.apache.xalan.internal.xsltc.dom.SingletonIterator;
import com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator;
-import com.sun.org.apache.xalan.internal.xsltc.dom.ArrayNodeListIterator;
+import com.sun.org.apache.xml.internal.dtm.Axis;
import com.sun.org.apache.xml.internal.dtm.DTM;
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
import com.sun.org.apache.xml.internal.dtm.DTMManager;
import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
-
-import org.w3c.dom.DOMException;
+import com.sun.org.apache.xml.internal.serializer.NamespaceMappings;
+import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
+import com.sun.org.apache.xml.internal.utils.XML11Char;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.FieldPosition;
+import java.text.MessageFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import com.sun.org.apache.xml.internal.serializer.NamespaceMappings;
-import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
-import com.sun.org.apache.xml.internal.utils.XML11Char;
/**
* Standard XSLT functions. All standard functions expect the current node
@@ -270,14 +267,15 @@ public final class BasisLibrary {
if (Double.isNaN(start))
return(EMPTYSTRING);
- final int strlen = value.length();
- int istart = (int)Math.round(start) - 1;
+ final int strlen = getStringLength(value);
+ int istart = (int)Math.round(start) - 1;
if (istart > strlen)
return(EMPTYSTRING);
if (istart < 1)
istart = 0;
try {
+ istart = value.offsetByCodePoints(0, istart);
return value.substring(istart);
} catch (IndexOutOfBoundsException e) {
runTimeError(RUN_TIME_INTERNAL_ERR, "substring()");
@@ -292,28 +290,35 @@ public final class BasisLibrary {
public static String substringF(String value, double start, double length) {
if (Double.isInfinite(start) ||
Double.isNaN(start) ||
- Double.isNaN(length))
+ Double.isNaN(length) ||
+ length < 0)
return(EMPTYSTRING);
- int istart = (int)Math.round(start) - 1;
+ int istart = (int)Math.round(start) - 1;
+ int ilength = (int)Math.round(length);
final int isum;
if (Double.isInfinite(length))
isum = Integer.MAX_VALUE;
else
- isum = istart + (int)Math.round(length);
+ isum = istart + ilength;
- final int strlen = value.length();
+ final int strlen = getStringLength(value);
if (isum < 0 || istart > strlen)
return(EMPTYSTRING);
- if (istart < 0)
+ if (istart < 0) {
+ ilength += istart;
istart = 0;
+ }
try {
- if (isum > strlen)
+ istart = value.offsetByCodePoints(0, istart);
+ if (isum > strlen) {
return value.substring(istart);
- else
- return value.substring(istart, isum);
+ } else {
+ int offset = value.offsetByCodePoints(istart, ilength);
+ return value.substring(istart, offset);
+ }
} catch (IndexOutOfBoundsException e) {
runTimeError(RUN_TIME_INTERNAL_ERR, "substring()");
return null;
@@ -975,7 +980,7 @@ public final class BasisLibrary {
/**
* Utility function: used to format/adjust a double to a string. The
- * DecimalFormat object comes from the 'formatSymbols' hashtable in
+ * DecimalFormat object comes from the 'formatSymbols' map in
* AbstractTranslet.
*/
private static FieldPosition _fieldPosition = new FieldPosition(0);