// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/40285824): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif // This is a copy of url/url_canon_internal.h circa 2023. It should be used only // by components/feedback/redaction_tool/. We need a copy because the // components/feedback/redaction_tool source code is shared into ChromeOS and // needs to have no dependencies outside of base/. #ifndef COMPONENTS_FEEDBACK_REDACTION_TOOL_URL_CANON_INTERNAL_H_ #define COMPONENTS_FEEDBACK_REDACTION_TOOL_URL_CANON_INTERNAL_H_ // This file is intended to be included in another C++ file where the character // types are defined. This allows us to write mostly generic code, but not have // template bloat because everything is inlined when anybody calls any of our // functions. #include <stddef.h> #include <stdlib.h> #include "components/feedback/redaction_tool/url_canon.h" namespace redaction_internal { // Character type handling ----------------------------------------------------- // Bits that identify different character types. These types identify different // bits that are set for each 8-bit character in the kSharedCharTypeTable. enum SharedCharTypes { … }; // This table contains the flags in SharedCharTypes for each 8-bit character. // Some canonicalization functions have their own specialized lookup table. // For those with simple requirements, we have collected the flags in one // place so there are fewer lookup tables to load into the CPU cache. // // Using an unsigned char type has a small but measurable performance benefit // over using a 32-bit number. extern const unsigned char kSharedCharTypeTable[0x100]; // More readable wrappers around the character type lookup table. inline bool IsCharOfType(unsigned char c, SharedCharTypes type) { … } inline bool IsQueryChar(unsigned char c) { … } inline bool IsIPv4Char(unsigned char c) { … } inline bool IsHexChar(unsigned char c) { … } inline bool IsComponentChar(unsigned char c) { … } #ifndef WIN32 // Implementations of Windows' int-to-string conversions int _itoa_s(int value, char* buffer, size_t size_in_chars, int radix); // Secure template overloads for these functions template <size_t N> inline int _itoa_s(int value, char (&buffer)[N], int radix) { … } // _strtoui64 and strtoull behave the same inline uint64_t _strtoui64(const char* nptr, char** endptr, int base) { … } #endif // WIN32 } // namespace redaction_internal #endif // COMPONENTS_FEEDBACK_REDACTION_TOOL_URL_CANON_INTERNAL_H_