/* Generated automatically by jlpp - do not edit. */ #include static jakelib::lang::String* jakelib2_strings[] = {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}; // "Match not yet attempted" static jchar chars_jakelib2_str_0[] = {77,97,116,99,104,32,110,111,116,32,121,101,116,32,97,116,116,101,109,112,116,101,100}; // "jakelib.util.regex.Matcher.start" static jchar chars_jakelib2_str_1[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,115,116,97,114,116}; // "No match found" static jchar chars_jakelib2_str_2[] = {78,111,32,109,97,116,99,104,32,102,111,117,110,100}; // "jakelib.util.regex.Matcher.start" static jchar chars_jakelib2_str_3[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,115,116,97,114,116}; // "start(" static jchar chars_jakelib2_str_4[] = {115,116,97,114,116,40}; // "): " static jchar chars_jakelib2_str_5[] = {41,58,32}; // " < 0" static jchar chars_jakelib2_str_6[] = {32,60,32,48}; // "jakelib.util.regex.Matcher.start" static jchar chars_jakelib2_str_7[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,115,116,97,114,116}; // "start(" static jchar chars_jakelib2_str_8[] = {115,116,97,114,116,40}; // "): " static jchar chars_jakelib2_str_9[] = {41,58,32}; // " >= " static jchar chars_jakelib2_str_10[] = {32,62,61,32}; // "jakelib.util.regex.Matcher.start" static jchar chars_jakelib2_str_11[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,115,116,97,114,116}; // "Match not yet attempted" static jchar chars_jakelib2_str_12[] = {77,97,116,99,104,32,110,111,116,32,121,101,116,32,97,116,116,101,109,112,116,101,100}; // "jakelib.util.regex.Matcher.end" static jchar chars_jakelib2_str_13[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,101,110,100}; // "No match found" static jchar chars_jakelib2_str_14[] = {78,111,32,109,97,116,99,104,32,102,111,117,110,100}; // "jakelib.util.regex.Matcher.end" static jchar chars_jakelib2_str_15[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,101,110,100}; // "end(" static jchar chars_jakelib2_str_16[] = {101,110,100,40}; // "): " static jchar chars_jakelib2_str_17[] = {41,58,32}; // " < 0" static jchar chars_jakelib2_str_18[] = {32,60,32,48}; // "jakelib.util.regex.Matcher.end" static jchar chars_jakelib2_str_19[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,101,110,100}; // "end(" static jchar chars_jakelib2_str_20[] = {101,110,100,40}; // "): " static jchar chars_jakelib2_str_21[] = {41,58,32}; // " >= " static jchar chars_jakelib2_str_22[] = {32,62,61,32}; // "jakelib.util.regex.Matcher.end" static jchar chars_jakelib2_str_23[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,101,110,100}; // "Match not yet attempted" static jchar chars_jakelib2_str_24[] = {77,97,116,99,104,32,110,111,116,32,121,101,116,32,97,116,116,101,109,112,116,101,100}; // "jakelib.util.regex.Matcher.group" static jchar chars_jakelib2_str_25[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,103,114,111,117,112}; // "No match found" static jchar chars_jakelib2_str_26[] = {78,111,32,109,97,116,99,104,32,102,111,117,110,100}; // "jakelib.util.regex.Matcher.group" static jchar chars_jakelib2_str_27[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,103,114,111,117,112}; // "group(" static jchar chars_jakelib2_str_28[] = {103,114,111,117,112,40}; // "): " static jchar chars_jakelib2_str_29[] = {41,58,32}; // " < 0" static jchar chars_jakelib2_str_30[] = {32,60,32,48}; // "jakelib.util.regex.Matcher.group" static jchar chars_jakelib2_str_31[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,103,114,111,117,112}; // "group(" static jchar chars_jakelib2_str_32[] = {103,114,111,117,112,40}; // "): " static jchar chars_jakelib2_str_33[] = {41,58,32}; // " >= " static jchar chars_jakelib2_str_34[] = {32,62,61,32}; // "jakelib.util.regex.Matcher.group" static jchar chars_jakelib2_str_35[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,77,97,116,99,104,101,114,46,103,114,111,117,112}; #line 1 "util/regex/Matcher.jlc" // -*- c++ -*- /* * jakelib2-regex - Regular Expressions for Jakelib2 * Copyright (C) 2003 Florian Wolff (florian@donuz.de) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: Matcher.jlc,v 1.4 2003/09/27 08:10:29 florian Exp $ */ #include "jakelib2.h" #include "jakelib2/util/regex/Matcher.h" #include "jakelib2/util/regex/Pattern.h" using namespace jakelib::lang; using namespace jakelib::util; using namespace jakelib::util::regex; JAKELIB_IMPLEMENT_CLASS("jakelib.util.regex.Matcher", Matcher, Object); //#pragma javasyntax /*****************************************************************************\ * Matcher | *****************************************************************************/ Matcher::Matcher(Pattern* pattern, String* input) { this->_pattern = pattern; resultsSize = (pattern->captureCount + 1) * 3; executed = false; results = (int*) malloc(sizeof(int) * resultsSize); reset(input); } Matcher::~Matcher() { free(results); } /*****************************************************************************\ * matches | *****************************************************************************/ jboolean Matcher::matches() { int rc = pcre_exec(_pattern->re, null, input->latin1(), input->length(), 0, 0, null, 0); return (rc >= 0); } /*****************************************************************************\ * pattern | *****************************************************************************/ Pattern* Matcher::pattern() { return _pattern; } /*****************************************************************************\ * groupCount | *****************************************************************************/ jint Matcher::groupCount() { return _pattern->captureCount; } /*****************************************************************************\ * find | *****************************************************************************/ jboolean Matcher::find(jint startIndex) { if (executed) { startIndex = results[1]; if (startIndex == previousStartIndex) startIndex ++; } substringCount = pcre_exec(_pattern->re, null, input->latin1(), input->length(), startIndex, 0, results, resultsSize); executed = true; previousStartIndex = startIndex; if (substringCount < 0) { return false; } else { return true; } } /*****************************************************************************\ * start | *****************************************************************************/ jint Matcher::start(jint idx) { if (!executed) throw new IllegalStateException(JAKELIB_ONDEMAND(jakelib2_strings[0], new jakelib::lang::String(chars_jakelib2_str_0, 0, 23)) ->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[1], new jakelib::lang::String(chars_jakelib2_str_1, 0, 32))))); if (substringCount < 0) throw new IllegalStateException(JAKELIB_ONDEMAND(jakelib2_strings[2], new jakelib::lang::String(chars_jakelib2_str_2, 0, 14)) ->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[3], new jakelib::lang::String(chars_jakelib2_str_3, 0, 32))))); if (idx < 0) throw new IllegalArgumentException(JAKELIB_ONDEMAND(jakelib2_strings[4], new jakelib::lang::String(chars_jakelib2_str_4, 0, 6)) ->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[5], new jakelib::lang::String(chars_jakelib2_str_5, 0, 3)) )->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[6], new jakelib::lang::String(chars_jakelib2_str_6, 0, 4)) )->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[7], new jakelib::lang::String(chars_jakelib2_str_7, 0, 32))))); if (idx >= substringCount) throw new IndexOutOfBoundsException(JAKELIB_ONDEMAND(jakelib2_strings[8], new jakelib::lang::String(chars_jakelib2_str_8, 0, 6)) ->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[9], new jakelib::lang::String(chars_jakelib2_str_9, 0, 3)) )->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[10], new jakelib::lang::String(chars_jakelib2_str_10, 0, 4)) )->plus( substringCount )->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[11], new jakelib::lang::String(chars_jakelib2_str_11, 0, 32))))); return results[idx * 2]; } /*****************************************************************************\ * end | *****************************************************************************/ jint Matcher::end(jint idx) { if (!executed) throw new IllegalStateException(JAKELIB_ONDEMAND(jakelib2_strings[12], new jakelib::lang::String(chars_jakelib2_str_12, 0, 23)) ->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[13], new jakelib::lang::String(chars_jakelib2_str_13, 0, 30))))); if (substringCount < 0) throw new IllegalStateException(JAKELIB_ONDEMAND(jakelib2_strings[14], new jakelib::lang::String(chars_jakelib2_str_14, 0, 14)) ->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[15], new jakelib::lang::String(chars_jakelib2_str_15, 0, 30))))); if (idx < 0) throw new IllegalArgumentException(JAKELIB_ONDEMAND(jakelib2_strings[16], new jakelib::lang::String(chars_jakelib2_str_16, 0, 4)) ->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[17], new jakelib::lang::String(chars_jakelib2_str_17, 0, 3)) )->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[18], new jakelib::lang::String(chars_jakelib2_str_18, 0, 4)) )->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[19], new jakelib::lang::String(chars_jakelib2_str_19, 0, 30))))); if (idx >= substringCount) throw new IndexOutOfBoundsException(JAKELIB_ONDEMAND(jakelib2_strings[20], new jakelib::lang::String(chars_jakelib2_str_20, 0, 4)) ->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[21], new jakelib::lang::String(chars_jakelib2_str_21, 0, 3)) )->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[22], new jakelib::lang::String(chars_jakelib2_str_22, 0, 4)) )->plus( substringCount )->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[23], new jakelib::lang::String(chars_jakelib2_str_23, 0, 30))))); return results[idx * 2 + 1]; } /*****************************************************************************\ * group | *****************************************************************************/ String* Matcher::group(jint idx) { if (!executed) throw new IllegalStateException(JAKELIB_ONDEMAND(jakelib2_strings[24], new jakelib::lang::String(chars_jakelib2_str_24, 0, 23)) ->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[25], new jakelib::lang::String(chars_jakelib2_str_25, 0, 32))))); if (substringCount < 0) throw new IllegalStateException(JAKELIB_ONDEMAND(jakelib2_strings[26], new jakelib::lang::String(chars_jakelib2_str_26, 0, 14)) ->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[27], new jakelib::lang::String(chars_jakelib2_str_27, 0, 32))))); if (idx < 0) throw new IllegalArgumentException(JAKELIB_ONDEMAND(jakelib2_strings[28], new jakelib::lang::String(chars_jakelib2_str_28, 0, 6)) ->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[29], new jakelib::lang::String(chars_jakelib2_str_29, 0, 3)) )->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[30], new jakelib::lang::String(chars_jakelib2_str_30, 0, 4)) )->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[31], new jakelib::lang::String(chars_jakelib2_str_31, 0, 32))))); if (idx >= substringCount) throw new IndexOutOfBoundsException(JAKELIB_ONDEMAND(jakelib2_strings[32], new jakelib::lang::String(chars_jakelib2_str_32, 0, 6)) ->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[33], new jakelib::lang::String(chars_jakelib2_str_33, 0, 3)) )->plus( idx )->plus( JAKELIB_ONDEMAND(jakelib2_strings[34], new jakelib::lang::String(chars_jakelib2_str_34, 0, 4)) )->plus( substringCount )->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[35], new jakelib::lang::String(chars_jakelib2_str_35, 0, 32))))); if (results[idx * 2] < 0) return new String(); else return input->substring(results[idx * 2], results[idx * 2 + 1]); } /*****************************************************************************\ * reset | *****************************************************************************/ void Matcher::reset() { executed = false; appendPosition = 0; previousStartIndex = 0; } void Matcher::reset(String* input) { this->input = input; reset(); } /*****************************************************************************\ * appendReplacement | *****************************************************************************/ void Matcher::appendReplacement(StringBuffer* buf, String* replacement) { jint startPos = start(); jint endPos = end(); buf->append(input->substring(appendPosition, startPos)); for (int x = 0; x < replacement->length(); x++) { jchar c = replacement->charAt(x); if (c == '$' && x < replacement->length() -1) { c = replacement->charAt(++x); if (c != '$') { int idx = (c - '0'); if (idx >= 0 && idx <= 9) buf->append(group(idx)); continue; } } buf->append(c); } appendPosition = endPos; } /*****************************************************************************\ * appendTail | *****************************************************************************/ void Matcher::appendTail(StringBuffer* buf) { buf->append(input->substring(appendPosition)); } /*****************************************************************************\ * replaceAll | *****************************************************************************/ String* Matcher::replaceAll(String* replacement) { StringBuffer buf; reset(); while (find()) { appendReplacement(&buf, replacement); } appendTail(&buf); return buf.toString(); }