Merge pull request #10148 from leezh/pcre2

Replacement of internal RegEx with PCRE2
This commit is contained in:
Rémi Verschelde
2017-08-31 11:56:19 +02:00
committed by GitHub
63 changed files with 88352 additions and 1411 deletions

View File

@ -1,7 +1,50 @@
#!/usr/bin/env python
Import('env')
Import('env_modules')
env.add_source_files(env.modules_sources, "*.cpp")
env_regex = env_modules.Clone()
env_regex.Append(CPPFLAGS=["-DPCRE2_CODE_UNIT_WIDTH=0"])
env_regex.add_source_files(env.modules_sources, "*.cpp")
Export('env')
if (env['builtin_pcre2'] != 'no'):
thirdparty_dir = "#thirdparty/pcre2/src/"
thirdparty_flags = ["-DPCRE2_STATIC", "-DHAVE_CONFIG_H", "-DSUPPORT_JIT"]
thirdparty_sources = [
"pcre2_auto_possess.c",
"pcre2_chartables.c",
"pcre2_compile.c",
"pcre2_config.c",
"pcre2_context.c",
"pcre2_dfa_match.c",
"pcre2_error.c",
"pcre2_find_bracket.c",
"pcre2_jit_compile.c",
"pcre2_maketables.c",
"pcre2_match.c",
"pcre2_match_data.c",
"pcre2_newline.c",
"pcre2_ord2utf.c",
"pcre2_pattern_info.c",
"pcre2_serialize.c",
"pcre2_string_utils.c",
"pcre2_study.c",
"pcre2_substitute.c",
"pcre2_substring.c",
"pcre2_tables.c",
"pcre2_ucd.c",
"pcre2_valid_utf.c",
"pcre2_xclass.c",
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env_regex.Append(CPPPATH=[thirdparty_dir])
env_regex.Append(CPPFLAGS=thirdparty_flags)
def pcre2_builtin(width):
env_pcre2 = env_modules.Clone()
env_pcre2["OBJSUFFIX"] = "_" + width + env_pcre2["OBJSUFFIX"]
env_pcre2.Append(CPPPATH=[thirdparty_dir])
env_pcre2.add_source_files(env.modules_sources, thirdparty_sources)
env_pcre2.Append(CPPFLAGS=thirdparty_flags)
env_pcre2.Append(CPPFLAGS=["-DPCRE2_CODE_UNIT_WIDTH=" + width])
pcre2_builtin("16")
pcre2_builtin("32")

File diff suppressed because it is too large Load Diff

View File

@ -31,59 +31,53 @@
#ifndef REGEX_H
#define REGEX_H
#include "core/array.h"
#include "core/dictionary.h"
#include "core/map.h"
#include "core/reference.h"
#include "core/resource.h"
#include "core/ustring.h"
#include "core/vector.h"
class RegExNode;
class RegExMatch : public Reference {
GDCLASS(RegExMatch, Reference);
struct Group {
Variant name;
struct Range {
int start;
int length;
int end;
};
Vector<Group> captures;
String string;
String subject;
Vector<Range> data;
Map<String, int> names;
friend class RegEx;
friend class RegExSearch;
friend class RegExNodeCapturing;
friend class RegExNodeBackReference;
protected:
static void _bind_methods();
int _find(const Variant &p_name) const;
public:
String expand(const String &p_template) const;
String get_subject() const;
int get_group_count() const;
Array get_group_array() const;
Array get_names() const;
Dictionary get_name_dict() const;
Dictionary get_names() const;
Array get_strings() const;
String get_string(const Variant &p_name) const;
int get_start(const Variant &p_name) const;
int get_end(const Variant &p_name) const;
RegExMatch();
};
class RegEx : public Resource {
class RegEx : public Reference {
GDCLASS(RegEx, Resource);
GDCLASS(RegEx, Reference);
RegExNode *root;
Vector<Variant> group_names;
void *general_ctx;
void *code;
String pattern;
int lookahead_depth;
void _pattern_info(uint32_t what, void *where) const;
protected:
static void _bind_methods();
@ -91,9 +85,10 @@ protected:
public:
void clear();
Error compile(const String &p_pattern);
void _init(const String &p_pattern = "");
Ref<RegExMatch> search(const String &p_text, int p_start = 0, int p_end = -1) const;
String sub(const String &p_text, const String &p_replacement, bool p_all = false, int p_start = 0, int p_end = -1) const;
Ref<RegExMatch> search(const String &p_subject, int offset = 0, int end = -1) const;
String sub(const String &p_subject, const String &p_replacement, bool p_all = false, int p_start = 0, int p_end = -1) const;
bool is_valid() const;
String get_pattern() const;