All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.saxon.regex.LatinString Maven / Gradle / Ivy

There is a newer version: 12.5
Show newest version
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2015 Saxonica Limited.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package net.sf.saxon.regex;

/**
 * An implementation of UnicodeString optimized for strings that contain
 * no characters outside the Latin-1 range (i.e. no characters whose codepoints exceed 255).
 */
public final class LatinString extends UnicodeString {

    private byte[] chars;

    public final static LatinString EMPTY = new LatinString(new byte[0]);
    public final static LatinString SINGLE_SPACE = new LatinString(new byte[]{(byte) 0x20});

    /**
     * Create a LatinString
     * @param src The string value. The caller must ensure that this contains no characters > 255
     */
    public LatinString(CharSequence src) {
        int len = src.length();
        chars = new byte[len];
        for (int i=0; i 255) {
            return -1;
        } else {
            for (int i = pos; i < chars.length; i++) {
                if ((chars[i] & 0xff) == search) {
                    return i;
                }
            }
            return -1;
        }
    }

    public int uLength() {
        return chars.length;
    }

    public boolean isEnd(int pos) {
        return pos >= chars.length;
    }

    public String toString() {
        char[] expanded = new char[chars.length];
        for (int i=0; ichars in the sequence.

* * @return the number of chars in this sequence */ public int length() { return chars.length; } /** * Returns the char value at the specified index. An index ranges from zero * to length() - 1. The first char value of the sequence is at * index zero, the next at index one, and so on, as for array * indexing.

*

*

If the char value specified by the index is a * surrogate, the surrogate * value is returned. * * @param index the index of the char value to be returned * @return the specified char value * @throws IndexOutOfBoundsException if the index argument is negative or not less than * length() */ public char charAt(int index) { return (char)(chars[index] & 0xff); } /** * Returns a new CharSequence that is a subsequence of this sequence. * The subsequence starts with the char value at the specified index and * ends with the char value at index end - 1. The length * (in chars) of the * returned sequence is end - start, so if start == end * then an empty sequence is returned.

* * @param start the start index, inclusive * @param end the end index, exclusive * @return the specified subsequence * @throws IndexOutOfBoundsException if start or end are negative, * if end is greater than length(), * or if start is greater than end */ public CharSequence subSequence(int start, int end) { return uSubstring(start, end); } @Override public boolean equals(Object obj) { return super.equals(obj); //To change body of overridden methods use File | Settings | File Templates. } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy