Java Code Examples for org.luaj.vm2.LuaString#indexOf()
The following examples show how to use
org.luaj.vm2.LuaString#indexOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringLib.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 4 votes |
public void format(Buffer buf, LuaString s) { int nullindex = s.indexOf((byte) '\0', 0); if (nullindex != -1) s = s.substring(0, nullindex); buf.append(s); }
Example 2
Source File: StringLib.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 4 votes |
/** * This utility method implements both string.find and string.match. */ static Varargs str_find_aux(Varargs args, boolean find) { LuaString s = args.checkstring(1); LuaString pat = args.checkstring(2); int init = args.optint(3, 1); if (init > 0) { init = Math.min(init - 1, s.length()); } else if (init < 0) { init = Math.max(0, s.length() + init); } boolean fastMatch = find && (args.arg(4).toboolean() || pat.indexOfAny(SPECIALS) == -1); if (fastMatch) { int result = s.indexOf(pat, init); if (result != -1) { return varargsOf(valueOf(result + 1), valueOf(result + pat.length())); } } else { MatchState ms = new MatchState(args, s, pat); boolean anchor = false; int poff = 0; if (pat.luaByte(0) == '^') { anchor = true; poff = 1; } int soff = init; do { int res; ms.reset(); if ((res = ms.match(soff, poff)) != -1) { if (find) { return varargsOf(valueOf(soff + 1), valueOf(res), ms.push_captures(false, soff, res)); } else { return ms.push_captures(true, soff, res); } } } while (soff++ < s.length() && !anchor); } return NIL; }
Example 3
Source File: StringLib.java From XPrivacyLua with GNU General Public License v3.0 | 4 votes |
public void format(Buffer buf, LuaString s) { int nullindex = s.indexOf( (byte)'\0', 0 ); if ( nullindex != -1 ) s = s.substring( 0, nullindex ); buf.append(s); }
Example 4
Source File: StringLib.java From XPrivacyLua with GNU General Public License v3.0 | 4 votes |
/** * This utility method implements both string.find and string.match. */ static Varargs str_find_aux( Varargs args, boolean find ) { LuaString s = args.checkstring( 1 ); LuaString pat = args.checkstring( 2 ); int init = args.optint( 3, 1 ); if ( init > 0 ) { init = Math.min( init - 1, s.length() ); } else if ( init < 0 ) { init = Math.max( 0, s.length() + init ); } boolean fastMatch = find && ( args.arg(4).toboolean() || pat.indexOfAny( SPECIALS ) == -1 ); if ( fastMatch ) { int result = s.indexOf( pat, init ); if ( result != -1 ) { return varargsOf( valueOf(result+1), valueOf(result+pat.length()) ); } } else { MatchState ms = new MatchState( args, s, pat ); boolean anchor = false; int poff = 0; if ( pat.luaByte( 0 ) == '^' ) { anchor = true; poff = 1; } int soff = init; do { int res; ms.reset(); if ( ( res = ms.match( soff, poff ) ) != -1 ) { if ( find ) { return varargsOf( valueOf(soff+1), valueOf(res), ms.push_captures( false, soff, res )); } else { return ms.push_captures( true, soff, res ); } } } while ( soff++ < s.length() && !anchor ); } return NIL; }
Example 5
Source File: StringLib.java From HtmlNative with Apache License 2.0 | 4 votes |
public void format(Buffer buf, LuaString s) { int nullindex = s.indexOf( (byte)'\0', 0 ); if ( nullindex != -1 ) s = s.substring( 0, nullindex ); buf.append(s); }
Example 6
Source File: StringLib.java From HtmlNative with Apache License 2.0 | 4 votes |
/** * This utility method implements both string.find and string.match. */ static Varargs str_find_aux( Varargs args, boolean find ) { LuaString s = args.checkstring( 1 ); LuaString pat = args.checkstring( 2 ); int init = args.optint( 3, 1 ); if ( init > 0 ) { init = Math.min( init - 1, s.length() ); } else if ( init < 0 ) { init = Math.max( 0, s.length() + init ); } boolean fastMatch = find && ( args.arg(4).toboolean() || pat.indexOfAny( SPECIALS ) == -1 ); if ( fastMatch ) { int result = s.indexOf( pat, init ); if ( result != -1 ) { return varargsOf( valueOf(result+1), valueOf(result+pat.length()) ); } } else { MatchState ms = new MatchState( args, s, pat ); boolean anchor = false; int poff = 0; if ( pat.luaByte( 0 ) == '^' ) { anchor = true; poff = 1; } int soff = init; do { int res; ms.reset(); if ( ( res = ms.match( soff, poff ) ) != -1 ) { if ( find ) { return varargsOf( valueOf(soff+1), valueOf(res), ms.push_captures( false, soff, res )); } else { return ms.push_captures( true, soff, res ); } } } while ( soff++ < s.length() && !anchor ); } return NIL; }
Example 7
Source File: StringLib.java From luaj with MIT License | 4 votes |
public void format(Buffer buf, LuaString s) { int nullindex = s.indexOf( (byte)'\0', 0 ); if ( nullindex != -1 ) s = s.substring( 0, nullindex ); buf.append(s); }
Example 8
Source File: StringLib.java From luaj with MIT License | 4 votes |
/** * This utility method implements both string.find and string.match. */ static Varargs str_find_aux( Varargs args, boolean find ) { LuaString s = args.checkstring( 1 ); LuaString pat = args.checkstring( 2 ); int init = args.optint( 3, 1 ); if ( init > 0 ) { init = Math.min( init - 1, s.length() ); } else if ( init < 0 ) { init = Math.max( 0, s.length() + init ); } boolean fastMatch = find && ( args.arg(4).toboolean() || pat.indexOfAny( SPECIALS ) == -1 ); if ( fastMatch ) { int result = s.indexOf( pat, init ); if ( result != -1 ) { return varargsOf( valueOf(result+1), valueOf(result+pat.length()) ); } } else { MatchState ms = new MatchState( args, s, pat ); boolean anchor = false; int poff = 0; if ( pat.length() > 0 && pat.luaByte( 0 ) == '^' ) { anchor = true; poff = 1; } int soff = init; do { int res; ms.reset(); if ( ( res = ms.match( soff, poff ) ) != -1 ) { if ( find ) { return varargsOf( valueOf(soff+1), valueOf(res), ms.push_captures( false, soff, res )); } else { return ms.push_captures( true, soff, res ); } } } while ( soff++ < s.length() && !anchor ); } return NIL; }