1 //===-- Twine.cpp - Fast Temporary String Concatenation -------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/Twine.h"
11 #include "llvm/Support/raw_ostream.h"
14 std::string Twine::str() const {
16 raw_string_ostream OS(Res);
21 void Twine::toVector(SmallVectorImpl<char> &Out) const {
22 raw_svector_ostream OS(Out);
26 void Twine::printOneChild(raw_ostream &OS, const void *Ptr,
27 NodeKind Kind) const {
29 case Twine::NullKind: break;
30 case Twine::EmptyKind: break;
31 case Twine::CStringKind:
32 OS << static_cast<const char*>(Ptr);
34 case Twine::StdStringKind:
35 OS << *static_cast<const std::string*>(Ptr);
37 case Twine::StringRefKind:
38 OS << *static_cast<const StringRef*>(Ptr);
40 case Twine::TwineKind:
41 static_cast<const Twine*>(Ptr)->print(OS);
46 void Twine::printOneChildRepr(raw_ostream &OS, const void *Ptr,
47 NodeKind Kind) const {
51 case Twine::EmptyKind:
53 case Twine::CStringKind:
55 << static_cast<const char*>(Ptr) << "\"";
57 case Twine::StdStringKind:
58 OS << "std::string:\""
59 << *static_cast<const std::string*>(Ptr) << "\"";
61 case Twine::StringRefKind:
63 << *static_cast<const StringRef*>(Ptr) << "\"";
65 case Twine::TwineKind:
67 static_cast<const Twine*>(Ptr)->printRepr(OS);
72 void Twine::print(raw_ostream &OS) const {
73 printOneChild(OS, LHS, getLHSKind());
74 printOneChild(OS, RHS, getRHSKind());
77 void Twine::printRepr(raw_ostream &OS) const {
79 printOneChildRepr(OS, LHS, getLHSKind());
81 printOneChildRepr(OS, RHS, getRHSKind());
85 void Twine::dump() const {
89 void Twine::dumpRepr() const {
90 printRepr(llvm::errs());