mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Use oniguruma’s default character type (OnigUChar)
This introduces a bunch of typecasts but means that less patching is required when updating the library.
This commit is contained in:
@@ -312,7 +312,7 @@ namespace find
|
||||
last_end = 0;
|
||||
|
||||
OnigErrorInfo einfo;
|
||||
int r = onig_new(&compiled_pattern, str.data(), str.data() + str.size(), (options & ignore_case ? ONIG_OPTION_IGNORECASE : 0) | ONIG_OPTION_CAPTURE_GROUP, ONIG_ENCODING_UTF8, ONIG_SYNTAX_RUBY, &einfo);
|
||||
int r = onig_new(&compiled_pattern, (OnigUChar const*)str.data(), (OnigUChar const*)str.data() + str.size(), (options & ignore_case ? ONIG_OPTION_IGNORECASE : 0) | ONIG_OPTION_CAPTURE_GROUP, ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT, &einfo);
|
||||
if(r != ONIG_NORMAL)
|
||||
{
|
||||
OnigUChar s[ONIG_MAX_ERROR_MESSAGE_LEN];
|
||||
@@ -360,11 +360,11 @@ namespace find
|
||||
else if(last_beg == last_end) // last match was zero-width, so advance one character to not repeat it
|
||||
++last_end;
|
||||
|
||||
char const* first = &buffer[0];
|
||||
char const* last = first + buffer.size();
|
||||
OnigUChar const* first = (OnigUChar const*)&buffer[0];
|
||||
OnigUChar const* last = first + buffer.size();
|
||||
|
||||
char const* range_start = first + last_end;
|
||||
char const* range_stop = last - skip_last;
|
||||
OnigUChar const* range_start = first + last_end;
|
||||
OnigUChar const* range_stop = last - skip_last;
|
||||
if(options & backwards)
|
||||
std::swap(range_start, range_stop);
|
||||
|
||||
@@ -411,7 +411,7 @@ namespace find
|
||||
}
|
||||
|
||||
private:
|
||||
regex_t* compiled_pattern;
|
||||
OnigRegex compiled_pattern;
|
||||
options_t options;
|
||||
std::vector<char> buffer;
|
||||
int last_beg, last_end;
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
|
||||
struct udata_t
|
||||
{
|
||||
UChar const* buffer;
|
||||
OnigUChar const* buffer;
|
||||
OnigRegion const* match;
|
||||
std::map<std::string, std::string>& res;
|
||||
};
|
||||
|
||||
static int copy_matches_for_name (UChar const* name, UChar const* name_end, int len, int* list, regex_t* pattern, void* udata)
|
||||
static int copy_matches_for_name (OnigUChar const* name, OnigUChar const* name_end, int len, int* list, OnigRegex pattern, void* udata)
|
||||
{
|
||||
udata_t const& data = *(udata_t const*)udata;
|
||||
UChar const* buffer = data.buffer;
|
||||
OnigUChar const* buffer = data.buffer;
|
||||
OnigRegion const* match = data.match;
|
||||
|
||||
std::string value = "";
|
||||
@@ -31,7 +31,7 @@ static int copy_matches_for_name (UChar const* name, UChar const* name_end, int
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> extract_captures (UChar const* buffer, OnigRegion const* match, regex_t* regexp)
|
||||
std::map<std::string, std::string> extract_captures (OnigUChar const* buffer, OnigRegion const* match, OnigRegex regexp)
|
||||
{
|
||||
std::map<std::string, std::string> res;
|
||||
for(size_t i = 0; i < match->num_regs; ++i)
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
#include "oniguruma.h"
|
||||
|
||||
std::map<std::string, std::string> extract_captures (UChar const* buffer, OnigRegion const* match, regex_t* regexp);
|
||||
std::map<std::string, std::string> extract_captures (OnigUChar const* buffer, OnigRegion const* match, OnigRegex regexp);
|
||||
|
||||
#endif /* end of include guard: ONIGURUMA_PRIVATE_H_IXPGSI3B */
|
||||
|
||||
@@ -12,17 +12,17 @@ namespace regexp
|
||||
|
||||
void pattern_t::init (std::string const& pattern, OnigOptionType options)
|
||||
{
|
||||
regex_t* tmp = NULL;
|
||||
OnigRegex tmp = NULL;
|
||||
|
||||
OnigErrorInfo einfo;
|
||||
int r = onig_new(&tmp, pattern.data(), pattern.data() + pattern.size(), options | ONIG_OPTION_CAPTURE_GROUP, ONIG_ENCODING_UTF8, ONIG_SYNTAX_RUBY, &einfo);
|
||||
int r = onig_new(&tmp, (OnigUChar const*)pattern.data(), (OnigUChar const*)pattern.data() + pattern.size(), options | ONIG_OPTION_CAPTURE_GROUP, ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT, &einfo);
|
||||
if(r == ONIG_NORMAL)
|
||||
{
|
||||
compiled_pattern.reset(tmp, onig_free);
|
||||
}
|
||||
else
|
||||
{
|
||||
char s[ONIG_MAX_ERROR_MESSAGE_LEN];
|
||||
OnigUChar s[ONIG_MAX_ERROR_MESSAGE_LEN];
|
||||
onig_error_code_to_str(s, r, &einfo);
|
||||
fprintf(stderr, "ERROR %s (%s)\n", s, pattern.c_str());
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace regexp
|
||||
std::map<std::string, std::string> const& match_t::captures () const
|
||||
{
|
||||
if(!captured_variables)
|
||||
captured_variables.reset(new std::map<std::string, std::string>(extract_captures(buffer(), region.get(), compiled_pattern.get())));
|
||||
captured_variables.reset(new std::map<std::string, std::string>(extract_captures((OnigUChar const*)buffer(), region.get(), compiled_pattern.get())));
|
||||
return *captured_variables;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace regexp
|
||||
{
|
||||
struct helper_t
|
||||
{
|
||||
static int main (UChar const* name, UChar const* name_end, int len, int* list, regex_t* pattern, void* udata)
|
||||
static int main (OnigUChar const* name, OnigUChar const* name_end, int len, int* list, OnigRegex pattern, void* udata)
|
||||
{
|
||||
match_t const& m = *((match_t const*)udata);
|
||||
foreach(it, list, list + len)
|
||||
@@ -113,7 +113,7 @@ namespace regexp
|
||||
{
|
||||
struct helper_t { static void region_free (OnigRegion* r) { onig_region_free(r, 1); } };
|
||||
regexp::region_ptr region(onig_region_new(), &helper_t::region_free);
|
||||
if(ONIG_MISMATCH != onig_search(ptrn.get().get(), first, last, from ?: first, to ?: last, region.get(), options))
|
||||
if(ONIG_MISMATCH != onig_search(ptrn.get().get(), (OnigUChar const*)first, (OnigUChar const*)last, (OnigUChar const*)(from ?: first), (OnigUChar const*)(to ?: last), region.get(), options))
|
||||
return match_t(region, ptrn.get(), first);
|
||||
}
|
||||
return match_t();
|
||||
@@ -131,17 +131,17 @@ namespace regexp
|
||||
std::string validate (std::string const& pattern)
|
||||
{
|
||||
OnigErrorInfo einfo;
|
||||
regex_t* tmp = NULL;
|
||||
int r = onig_new(&tmp, pattern.data(), pattern.data() + pattern.size(), ONIG_OPTION_CAPTURE_GROUP, ONIG_ENCODING_UTF8, ONIG_SYNTAX_RUBY, &einfo);
|
||||
OnigRegex tmp = NULL;
|
||||
int r = onig_new(&tmp, (OnigUChar const*)pattern.data(), (OnigUChar const*)pattern.data() + pattern.size(), ONIG_OPTION_CAPTURE_GROUP, ONIG_ENCODING_UTF8, ONIG_SYNTAX_DEFAULT, &einfo);
|
||||
if(tmp)
|
||||
onig_free(tmp);
|
||||
|
||||
std::string error = NULL_STR;
|
||||
if(r != ONIG_NORMAL)
|
||||
{
|
||||
char s[ONIG_MAX_ERROR_MESSAGE_LEN];
|
||||
OnigUChar s[ONIG_MAX_ERROR_MESSAGE_LEN];
|
||||
onig_error_code_to_str(s, r, &einfo);
|
||||
error = s;
|
||||
error = std::string(s, s + strlen((char const*)s));
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user