Skip to content

Commit

Permalink
added Ustr code and Java 5 support to mutable-string branch
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.codehaus.org/jruby/branches/mutable-string@2238 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information
headius committed Sep 26, 2006
1 parent e336029 commit e2380cd
Show file tree
Hide file tree
Showing 5 changed files with 1,535 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .settings/org.eclipse.jdt.core.prefs
@@ -1,12 +1,12 @@
#Mon Jan 02 00:48:54 CST 2006
#Mon Sep 25 23:02:20 CDT 2006
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.source=1.4
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
4 changes: 2 additions & 2 deletions .settings/org.eclipse.jdt.ui.prefs
@@ -1,3 +1,3 @@
#Thu Sep 29 15:25:20 CDT 2005
#Mon Sep 25 23:02:20 CDT 2006
eclipse.preferences.version=1
internal.default.compliance=user
internal.default.compliance=default
78 changes: 78 additions & 0 deletions src/org/jruby/util/string/UcharIterator.java
@@ -0,0 +1,78 @@
package org.jruby.util.string;

/**
* UcharIterator - an Iterator on Unicode characters in a UTF-8 byte array.
*
* <p>A conventional Iterator, remove() is not supported, and there's an extra
* nextChar() method that returns a naked int as opposed to a wrapped Integer.
* </p>
*
* @author Tim Bray
* @see org.jruby.util.string.Ustr
*/

public class UcharIterator implements java.util.Iterator, java.io.Serializable {
private Ustr u;
private int next;

/**
* Creates a new UcharIterator starting at an offset in a buffer.
*
* @param s the byte array containing UTF-8-encoded Unicode characters.
* @param offset how far into the array to start iterating.
*/
public UcharIterator(byte[] s, int offset) {
u = new Ustr(s, offset);
u.prepareNext();
next = u.nextChar();
}

/**
* Tests whether there are any more characters in the buffer.
*
* @return true or false depending on whether there are more characters.
*/
public boolean hasNext() {
return (next != 0);
}

/**
* Retrieve the next Unicode character from a UTF-8 byte buffer, wrapped
* in an Integer object. Throws NoSuchElementException if hasNext
* would return false.
*
* @return the next Unicode character as a java.lang.Integer
* @throws NoSuchElementException
*/
public Object next() {
if (next == 0)
throw new java.util.NoSuchElementException("Ran off end of array");
Integer i = new Integer(next);
next = u.nextChar();
return i;
}

/**
* Retrieve the next Unicode character from a UTF-8 byte buffer and return
* it as an int. Once the null-termination is hit, returns 0 as many times
* as you want to call it.
*
* @return the next Unicode character as an int, 0 on end-of-string.
*/
public int nextChar() {
int i = next;
if (i != 0)
next = u.nextChar();
return i;
}

/**
* Throws an UnsupportedOperationException.
*
* @throws UnsupportedOperationException
*/
public void remove() {
throw new UnsupportedOperationException("UcharIterator doesn't remove");
}

}

0 comments on commit e2380cd

Please sign in to comment.