fix logic
[personal-kdelibs.git] / kjs / regexp.h
blob4bbd5bf32c67155509c23d013f161e747a95bb25
1 // -*- c-basic-offset: 2 -*-
2 /*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef _KJS_REGEXP_H_
23 #define _KJS_REGEXP_H_
25 #include <sys/types.h>
27 #include "global.h"
29 #include <config.h>
31 #ifdef HAVE_PCREPOSIX
32 #include <pcre.h>
33 #else // POSIX regex - not so good...
34 extern "C" { // bug with some libc5 distributions
35 #include <regex.h>
37 #endif //HAVE_PCREPOSIX
39 #include "ustring.h"
41 namespace KJS {
43 class RegExp {
44 public:
45 enum { None = 0, Global = 1, IgnoreCase = 2, Multiline = 4 };
47 explicit RegExp(const UString &pattern, char flags = None);
48 ~RegExp();
50 char flags() const { return _flags; }
51 bool isValid() const { return _valid; }
53 UString match(const UString &s, bool *error, int i, int *pos = 0, int **ovector = 0);
54 unsigned subPatterns() const { return _numSubPatterns; }
55 UString pattern() const { return _pat; }
57 //These methods should be called around the match of the same string..
58 void prepareMatch(const UString &s);
59 void doneMatch();
61 private:
62 #ifdef HAVE_PCREPOSIX
63 pcre *_regex;
64 #else
65 regex_t _regex;
66 #endif
67 UString _pat;
68 char _flags;
69 bool _valid;
70 unsigned _numSubPatterns;
72 // Cached encoding info...
73 char* _buffer;
74 int* _originalPos;
75 int _bufferSize;
77 void prepareUtf8 (const UString& s);
78 void prepareASCII (const UString& s);
79 #ifndef NDEBUG
80 UString _originalS; // the original string, used for sanity-checking
81 #endif
83 RegExp(const RegExp &);
84 RegExp &operator=(const RegExp &);
86 enum UTF8SupportState {
87 Unknown,
88 Supported,
89 Unsupported
92 static UTF8SupportState utf8Support;
95 } // namespace
97 #endif