Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.temp.common.shared.utils;

/**
 * Code to Treat a String as a sorta Iterator...
 */
public class CharSource {
    private String mSource;
    private int mFrom, mTo;

    public CharSource( String pSource, int pFrom ) {
        mSource = StringUtils.deNull( pSource );
        if ( (mFrom = pFrom) < 0 ) {
            throw new IllegalArgumentException( "'From' not allowed to be negative" );
        }
        mTo = mSource.length();
    }

    public CharSource( String pSource ) {
        this( pSource, 0 );
    }

    public CharSource( String pSource, int pFrom, int pTo ) {
        this( pSource, pFrom );
        if ( pTo > mTo ) {
            throw new IllegalArgumentException( "'To' not allowed to be greater than the length of the 'Source' string" );
        }
        if ( pTo < 0 ) {
            mTo += pTo;
        } else {
            mTo = pTo;
        }
    }

    public boolean anyRemaining() {
        return (mFrom < mTo);
    }

    public int peek() {
        return anyRemaining() ? mSource.charAt( mFrom ) : -1;
    }

    public int get() {
        return anyRemaining() ? mSource.charAt( mFrom++ ) : -1;
    }

    public char getRequired() {
        if ( anyRemaining() ) {
            return mSource.charAt( mFrom++ );
        }
        throw new IllegalArgumentException( "Unexpected EOD encountered at index " + mFrom + " in " + mSource );
    }

    public String getUpTo( char c ) {
        int at = mSource.indexOf( c, mFrom );
        if ( at == -1 ) {
            return "";
        }
        String rv = mSource.substring( mFrom, at );
        mFrom = at;
        return rv;
    }

    public boolean consumeSpaces() {
        while ( peek() == ' ' ) {
            mFrom++;
        }
        return anyRemaining();
    }

    public String getUpToNonVisible7BitAscii() {
        if ( !anyRemaining() ) {
            return "";
        }
        int zFrom = mFrom;
        for ( int c = peek(); (c != -1) && ((' ' < c) && (c <= 126)); c = peek() ) {
            mFrom++;
        }
        return mSource.substring( zFrom, mFrom );
    }

    public boolean consumeNonVisible7BitAscii() {
        for ( int c = peek(); (c != -1) && ((c <= ' ') || (126 < c)); c = peek() ) {
            mFrom++;
        }
        return anyRemaining();
    }

    public int getFrom() {
        return mFrom;
    }

    public int getLastFrom() {
        return mFrom - 1;
    }

    @Override
    public String toString() {
        return mSource.substring( mFrom, mTo );
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/common/shared/utils/CharSource.java

Diff revisions: vs.
Revision Author Commited Message
964 GeorgeS picture GeorgeS Fri 01 Aug, 2014 03:18:23 +0000

!