#include "base/i18n/rtl.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <string_view>
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/containers/fixed_flat_set.h"
#include "base/files/file_path.h"
#include "base/i18n/base_i18n_switches.h"
#include "base/logging.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "third_party/icu/source/common/unicode/locid.h"
#include "third_party/icu/source/common/unicode/uchar.h"
#include "third_party/icu/source/common/unicode/uscript.h"
#include "third_party/icu/source/i18n/unicode/coll.h"
#if BUILDFLAG(IS_IOS)
#include "base/debug/crash_logging.h"
#include "base/ios/ios_util.h"
#endif
namespace {
std::string GetLocaleString(const icu::Locale& locale) { … }
base::i18n::TextDirection GetCharacterDirection(UChar32 character) { … }
}
namespace base::i18n {
static TextDirection g_icu_text_direction = …;
std::string GetConfiguredLocale() { … }
std::string GetCanonicalLocale(const std::string& locale) { … }
std::string ICULocaleName(const std::string& locale_string) { … }
void SetICUDefaultLocale(const std::string& locale_string) { … }
bool IsRTL() { … }
void SetRTLForTesting(bool rtl) { … }
bool ICUIsRTL() { … }
TextDirection GetForcedTextDirection() { … }
TextDirection GetTextDirectionForLocaleInStartUp(const char* locale_name) { … }
TextDirection GetTextDirectionForLocale(const char* locale_name) { … }
TextDirection GetFirstStrongCharacterDirection(const std::u16string& text) { … }
TextDirection GetLastStrongCharacterDirection(const std::u16string& text) { … }
TextDirection GetStringDirection(const std::u16string& text) { … }
#if BUILDFLAG(IS_WIN)
bool AdjustStringForLocaleDirection(std::u16string* text) {
if (!IsRTL() || text->empty())
return false;
bool has_rtl_chars = StringContainsStrongRTLChars(*text);
if (!has_rtl_chars)
WrapStringWithLTRFormatting(text);
else
WrapStringWithRTLFormatting(text);
return true;
}
bool UnadjustStringForLocaleDirection(std::u16string* text) {
if (!IsRTL() || text->empty())
return false;
*text = StripWrappingBidiControlCharacters(*text);
return true;
}
#else
bool AdjustStringForLocaleDirection(std::u16string* text) { … }
bool UnadjustStringForLocaleDirection(std::u16string* text) { … }
#endif
void EnsureTerminatedDirectionalFormatting(std::u16string* text) { … }
void SanitizeUserSuppliedString(std::u16string* text) { … }
bool StringContainsStrongRTLChars(const std::u16string& text) { … }
void WrapStringWithLTRFormatting(std::u16string* text) { … }
void WrapStringWithRTLFormatting(std::u16string* text) { … }
void WrapPathWithLTRFormatting(const FilePath& path,
std::u16string* rtl_safe_path) { … }
std::u16string GetDisplayStringInLTRDirectionality(const std::u16string& text) { … }
std::u16string StripWrappingBidiControlCharacters(const std::u16string& text) { … }
}