mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Previously it was part of swiftBasic. The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library. This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling. Also in this commit: remove some unused API functions from the demangler Context. fixes rdar://problem/30503344
66 lines
2.5 KiB
C++
66 lines
2.5 KiB
C++
//===--- Punycode.h - UTF-8 to Punycode transcoding -------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// These functions implement a variant of the Punycode algorithm from RFC3492,
|
|
// originally designed for encoding international domain names, for the purpose
|
|
// of encoding Swift identifiers into mangled symbol names. This version differs
|
|
// from RFC3492 in the following respects:
|
|
// - '_' is used as the encoding delimiter instead of '-'.
|
|
// - Encoding digits are represented using [a-zA-J] instead of [a-z0-9], because
|
|
// symbol names are case-sensitive, and Swift mangled identifiers cannot begin
|
|
// with a digit.
|
|
// - Optionally, non-symbol ASCII characters (characters except [$_a-zA-Z0-9])
|
|
// are mapped to the code range 0xD800 - 0xD880 and are also encoded like
|
|
// non-ASCII unicode characters.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_DEMANGLING_PUNYCODE_H
|
|
#define SWIFT_DEMANGLING_PUNYCODE_H
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include <vector>
|
|
#include <cstdint>
|
|
|
|
namespace swift {
|
|
namespace Punycode {
|
|
|
|
using llvm::StringRef;
|
|
|
|
/// Encodes a sequence of code points into Punycode.
|
|
///
|
|
/// Returns false if input contains surrogate code points.
|
|
bool encodePunycode(const std::vector<uint32_t> &InputCodePoints,
|
|
std::string &OutPunycode);
|
|
|
|
/// Decodes a Punycode string into a sequence of Unicode scalars.
|
|
///
|
|
/// Returns false if decoding failed.
|
|
bool decodePunycode(StringRef InputPunycode,
|
|
std::vector<uint32_t> &OutCodePoints);
|
|
|
|
/// Encodes an UTF8 string into Punycode.
|
|
///
|
|
/// If \p mapNonSymbolChars is true, non-symbol ASCII characters (characters
|
|
/// except [$_a-zA-Z0-9]) are also encoded like non-ASCII unicode characters.
|
|
/// Returns false if \p InputUTF8 contains surrogate code points.
|
|
bool encodePunycodeUTF8(StringRef InputUTF8, std::string &OutPunycode,
|
|
bool mapNonSymbolChars = false);
|
|
|
|
bool decodePunycodeUTF8(StringRef InputPunycode, std::string &OutUTF8);
|
|
|
|
} // end namespace Punycode
|
|
} // end namespace swift
|
|
|
|
#endif // SWIFT_DEMANGLING_PUNYCODE_H
|
|
|