From 48921c35e00ec6840ee535e16db8c9acd09bc1c7 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 5 Feb 2013 18:20:22 -0800 Subject: [PATCH] Use ICU for checking if characters are whitespace --- aegisub/src/utils.cpp | 12 +++--------- aegisub/src/utils.h | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/aegisub/src/utils.cpp b/aegisub/src/utils.cpp index d5a8634f1..4a143ef4f 100644 --- a/aegisub/src/utils.cpp +++ b/aegisub/src/utils.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -108,15 +109,8 @@ int SmallestPowerOf2(int x) { return x; } -bool IsWhitespace(wchar_t c) { - const wchar_t whitespaces[] = { - // http://en.wikipedia.org/wiki/Space_(punctuation)#Table_of_spaces - 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0, - 0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, - 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x2028, 0x2029, 0x202F, - 0x025F, 0x3000, 0xFEFF - }; - return std::binary_search(whitespaces, std::end(whitespaces), c); +bool IsWhitespace(wxUniChar c) { + return !!u_isUWhiteSpace(c.GetValue()); } bool StringEmptyOrWhitespace(const wxString &str) { diff --git a/aegisub/src/utils.h b/aegisub/src/utils.h index be4a9857f..f4331aacd 100644 --- a/aegisub/src/utils.h +++ b/aegisub/src/utils.h @@ -62,7 +62,7 @@ void StatusTimeout(wxString const& msg, int ms = 10000); int SmallestPowerOf2(int x); /// Check if wchar 'c' is a whitespace character -bool IsWhitespace(wchar_t c); +bool IsWhitespace(wxUniChar c); /// Check if every character in str is whitespace bool StringEmptyOrWhitespace(const wxString &str);