chromium/base/i18n/rtl.cc

// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// Extract language, country and variant, but ignore keywords.  For example,
// en-US, ca@valencia, ca-ES@valencia.
std::string GetLocaleString(const icu::Locale& locale) {}

// Returns LEFT_TO_RIGHT or RIGHT_TO_LEFT if |character| has strong
// directionality, returns UNKNOWN_DIRECTION if it doesn't. Please refer to
// http://unicode.org/reports/tr9/ for more information.
base::i18n::TextDirection GetCharacterDirection(UChar32 character) {}

}  // namespace

namespace base::i18n {

// Represents the locale-specific ICU text direction.
static TextDirection g_icu_text_direction =;

// Convert the ICU default locale to a string.
std::string GetConfiguredLocale() {}

// Convert the ICU canonicalized locale to a string.
std::string GetCanonicalLocale(const std::string& locale) {}

// Convert Chrome locale name to ICU locale name
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;

  // Marking the string as LTR if the locale is RTL and the string does not
  // contain strong RTL characters. Otherwise, mark the string as RTL.
  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  // !BUILDFLAG(IS_WIN)

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) {}

}  // namespace base::i18n