mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Cleaned up regex used for literals matching and replacement. Changed literal patterns to use non-capturing groups for performance.
This commit is contained in:
@@ -218,7 +218,7 @@ namespace Orchard.Framework.Tests.Localization {
|
||||
}
|
||||
|
||||
private DateParts GetExpectedDateParts(DateTime date, string format) {
|
||||
var formatWithoutLiterals = Regex.Replace(format, @"((?<!\\)'(.*?)((?<!\\)')|(?<!\\)""(.*?)((?<!\\)""))", "");
|
||||
var formatWithoutLiterals = Regex.Replace(format, @"(?<!\\)'(.*?)(?<!\\)'|(?<!\\)""(.*?)(?<!\\)""", "");
|
||||
return new DateParts(
|
||||
formatWithoutLiterals.Contains('y') ? date.Year : 0,
|
||||
formatWithoutLiterals.Contains('M') ? date.Month : 0,
|
||||
@@ -227,7 +227,7 @@ namespace Orchard.Framework.Tests.Localization {
|
||||
}
|
||||
|
||||
private TimeParts GetExpectedTimeParts(DateTime time, string format) {
|
||||
var formatWithoutLiterals = Regex.Replace(format, @"((?<!\\)'(.*?)((?<!\\)')|(?<!\\)""(.*?)((?<!\\)""))", "");
|
||||
var formatWithoutLiterals = Regex.Replace(format, @"(?<!\\)'(.*?)(?<!\\)'|(?<!\\)""(.*?)(?<!\\)""", "");
|
||||
return new TimeParts(
|
||||
formatWithoutLiterals.Contains('H') || format.Contains('h') ? time.Hour : 0,
|
||||
formatWithoutLiterals.Contains('m') ? time.Minute : 0,
|
||||
|
@@ -323,7 +323,8 @@ namespace Orchard.Framework.Localization.Services {
|
||||
result = EscapeForRegex(result);
|
||||
|
||||
// Transform all literals to corresponding wildcard matches.
|
||||
result = Regex.Replace(result, @"(?<!\\)'(.*?)((?<!\\)')", m => String.Format("(.{{{0}}})", m.Value.Replace("\\", "").Length - 2));
|
||||
//result = Regex.Replace(result, @"(?<!\\)'(.*?)(?<!\\)'|(?<!\\)""(.*?)(?<!\\)""", m => EscapeForRegex(m.Value.Trim('\'', '"')));
|
||||
result = Regex.Replace(result, @"(?<!\\)'(.*?)(?<!\\)'|(?<!\\)""(.*?)(?<!\\)""", m => String.Format("(?:.{{{0}}})", m.Value.Replace("\\", "").Length - 2));
|
||||
|
||||
// Transform all DateTime format specifiers into corresponding Regex captures.
|
||||
result = result.ReplaceAll(replacements);
|
||||
|
@@ -42,9 +42,7 @@ struct DateLocalizationOptions {
|
||||
|
||||
TODO:
|
||||
* Test for proper handling of fraction (f) format specifier - suspect it does not work properly in current state
|
||||
* Literal parts in format strings should be transformed to corresponding literal in Regex, not just into a wildcard, otherwise the resulting wildcard in some cases will match subsequent non-literal parts of the date/time string.
|
||||
* Rewrite DefaultDateLocalizationServices
|
||||
* Write unit tests for DefaultDateLocalizationServices
|
||||
* Add warning message when saving unsupported combination in settings
|
||||
* Add support for the different Gregorian calendar types
|
||||
* User ICultureManager and ICultureRepository to get the current CultureInfo in other classes
|
Reference in New Issue
Block a user