1 //===- lib/MC/MCSymbol.cpp - MCSymbol implementation ----------------------===//
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/MC/MCSymbol.h"
11 #include "llvm/Support/raw_ostream.h"
15 /// NeedsQuoting - Return true if the string \arg Str needs quoting, i.e., it
16 /// does not match [a-zA-Z_.][a-zA-Z0-9_.]*.
18 // FIXME: This could be more permissive, do we care?
19 static inline bool NeedsQuoting(const StringRef &Str) {
23 // Check that first character is in [a-zA-Z_.].
24 if (!((Str[0] >= 'a' && Str[0] <= 'z') ||
25 (Str[0] >= 'A' && Str[0] <= 'Z') ||
26 (Str[0] == '_' || Str[0] == '.')))
29 // Check subsequent characters are in [a-zA-Z0-9_.].
30 for (unsigned i = 1, e = Str.size(); i != e; ++i)
31 if (!((Str[i] >= 'a' && Str[i] <= 'z') ||
32 (Str[i] >= 'A' && Str[i] <= 'Z') ||
33 (Str[i] >= '0' && Str[i] <= '9') ||
34 (Str[i] == '_' || Str[i] == '.')))
40 void MCSymbol::print(raw_ostream &OS) const {
41 if (NeedsQuoting(getName()))
42 OS << '"' << getName() << '"';
47 void MCSymbol::dump() const {