Skip to content

Commit f954742

Browse files
committed
Add fromChars() to CharTraitsT, to convert from const char* to string_type
This is a cheap fix, to ensure that match_results::format() gets the right encoding. It'd be nice to fix these converters such that we only do the conversion rather than the multiple alloc/dealloc/convert-to-string mess that we're doing now.
1 parent fa87cb8 commit f954742

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

PythonScript/src/Replacer.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ int BoostRegexMatch<CharTraitsT>::groupIndexFromName(const char *groupName)
138138
template <class CharTraitsT>
139139
void BoostRegexMatch<CharTraitsT>::expand(const char *format, char **result, int *resultLength)
140140
{
141-
CharTraitsT::string_type resultString = m_match->format(format, boost::regex_constants::format_all);
141+
CharTraitsT::string_type formatString = CharTraitsT::fromChars(format);
142+
CharTraitsT::string_type resultString = m_match->format(formatString, boost::regex_constants::format_all);
142143

143144
std::string charResult(CharTraitsT::toCharString(resultString));
144145

@@ -166,6 +167,10 @@ typename std::string BoostRegexMatch<CharTraitsT>::getTextForGroup(GroupDetail*
166167
// We just want a u32string to utf8 char*
167168
return std::basic_string<char>(UtfConversion::toUtf8(ConstString<U32>(source)));
168169
}
170+
171+
static string_type fromChars(const char *source) {
172+
return string_type(UtfConversion::toUtf32(ConstString<U8>(source)));
173+
}
169174
};
170175

171176
class AnsiCharTraits {
@@ -178,6 +183,10 @@ typename std::string BoostRegexMatch<CharTraitsT>::getTextForGroup(GroupDetail*
178183
static std::basic_string<char> toCharString(const string_type& source) {
179184
return source;
180185
}
186+
187+
static string_type fromChars(const char *source) {
188+
return string_type(source);
189+
}
181190
};
182191

183192
template <class CharTraitsT>

0 commit comments

Comments
 (0)