/* Generated automatically by jlpp - do not edit. */ #include static jakelib::lang::String* jakelib2_strings[] = {null, null, null, null, null, null, null}; // "Compilation of regular expression failed at offset " static jchar chars_jakelib2_str_0[] = {67,111,109,112,105,108,97,116,105,111,110,32,111,102,32,114,101,103,117,108,97,114,32,101,120,112,114,101,115,115,105,111,110,32,102,97,105,108,101,100,32,97,116,32,111,102,102,115,101,116,32}; // ": " static jchar chars_jakelib2_str_1[] = {58,32}; // "jakelib.util.regex.Pattern.Pattern" static jchar chars_jakelib2_str_2[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,80,97,116,116,101,114,110,46,80,97,116,116,101,114,110}; // "Compilation of regular expression failed" static jchar chars_jakelib2_str_3[] = {67,111,109,112,105,108,97,116,105,111,110,32,111,102,32,114,101,103,117,108,97,114,32,101,120,112,114,101,115,115,105,111,110,32,102,97,105,108,101,100}; // "jakelib.util.regex.Pattern.Pattern" static jchar chars_jakelib2_str_4[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,80,97,116,116,101,114,110,46,80,97,116,116,101,114,110}; // "jakelib.util.regex.Pattern.compile" static jchar chars_jakelib2_str_5[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,80,97,116,116,101,114,110,46,99,111,109,112,105,108,101}; // "jakelib.util.regex.Pattern.compile" static jchar chars_jakelib2_str_6[] = {106,97,107,101,108,105,98,46,117,116,105,108,46,114,101,103,101,120,46,80,97,116,116,101,114,110,46,99,111,109,112,105,108,101}; #line 1 "util/regex/Pattern.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: Pattern.jlc,v 1.6 2003/09/27 08:10:29 florian Exp $ */ #include "jakelib2.h" #include "jakelib2/util/regex/Matcher.h" #include "jakelib2/util/regex/Pattern.h" #include "jakelib2/util/regex/PatternSyntaxException.h" #include "jakelib2/lang/System.h" #include "jakelib2/util/ArrayList.h" using namespace jakelib::lang; using namespace jakelib::util; using namespace jakelib::util::regex; JAKELIB_IMPLEMENT_CLASS("jakelib.util.regex.Pattern", Pattern, Object); const jint Pattern::CASE_INSENSITIVE = PCRE_CASELESS; const jint Pattern::MULTILINE = PCRE_MULTILINE; const jint Pattern::DOTALL = PCRE_DOTALL; //#pragma javasyntax /*****************************************************************************\ * Pattern | *****************************************************************************/ Pattern::Pattern(String* pattern, jint flags) { this->_pattern = pattern; this->_flags = flags; const char* error; int erroffset; re = pcre_compile(pattern->latin1(), flags, &error, &erroffset, NULL); if (re == null) { throw new PatternSyntaxException(JAKELIB_ONDEMAND(jakelib2_strings[0], new jakelib::lang::String(chars_jakelib2_str_0, 0, 51)) ->plus( erroffset )->plus( JAKELIB_ONDEMAND(jakelib2_strings[1], new jakelib::lang::String(chars_jakelib2_str_1, 0, 2)) )->plus( (char*)error )->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[2], new jakelib::lang::String(chars_jakelib2_str_2, 0, 34))))); } int rc = pcre_fullinfo(re, null, PCRE_INFO_CAPTURECOUNT, &captureCount); if (rc) throw new PatternSyntaxException(JAKELIB_ONDEMAND(jakelib2_strings[3], new jakelib::lang::String(chars_jakelib2_str_3, 0, 40)) ->plus( JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[4], new jakelib::lang::String(chars_jakelib2_str_4, 0, 34))))); } Pattern::~Pattern() { //(pcre_free)(re); free(re); } /*****************************************************************************\ * compile | *****************************************************************************/ Pattern* Pattern::compile(String* pattern, jint flags) { if (pattern == null) throw new NullPointerException(JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[5], new jakelib::lang::String(chars_jakelib2_str_5, 0, 34)))); return new Pattern(pattern, flags); } Pattern* Pattern::compile(char* pattern, jint flags) { if (pattern == null) throw new NullPointerException(JAKELIB_AT(JAKELIB_ONDEMAND(jakelib2_strings[6], new jakelib::lang::String(chars_jakelib2_str_6, 0, 34)))); return new Pattern(new String(pattern), flags); } /*****************************************************************************\ * pattern | *****************************************************************************/ String* Pattern::pattern() { return _pattern; } /*****************************************************************************\ * flags | *****************************************************************************/ jint Pattern::flags() { return _flags; } /*****************************************************************************\ * matcher | *****************************************************************************/ Matcher* Pattern::matcher(String* input) { return new Matcher(this, input); } Matcher* Pattern::matcher(char* input) { return new Matcher(this, new String(input)); } /*****************************************************************************\ * matches | *****************************************************************************/ jboolean Pattern::matches(String* pattern, String* input) { Pattern* p = Pattern::compile(pattern); jboolean rc = p->matcher(input)->matches(); delete p; return rc; } jboolean Pattern::matches(char* pattern, char* input) { String pat(pattern); Pattern* p = Pattern::compile(&pat); jboolean rc = p->matcher(input)->matches(); delete p; return rc; } /*****************************************************************************\ * split | *****************************************************************************/ ArrayList* Pattern::split(char* input, jint limit) { String _input(input); return split(&_input, limit); } ArrayList* Pattern::split(String* input, jint limit) { Matcher* m = matcher(input); ArrayList* l = new ArrayList(); jint startIndex = 0; while(m->find()) { jint endIndex = m->start(); if (endIndex > startIndex) { if (limit > 0 && l->size() == limit -1) { l->add(input->substring(startIndex)); return l; } l->add(input->substring(startIndex, endIndex)); } startIndex = m->end(); } if (startIndex < input->length()) l->add(input->substring(startIndex)); return l; }