- // Mangle the first letter specially, don't allow numbers...
- if ((X[0] < 'a' || X[0] > 'z') && (X[0] < 'A' || X[0] > 'Z') && X[0] != '_')
- Result += MangleLetter(X[0]);
- else
- Result += X[0];
-
- for (std::string::const_iterator I = X.begin()+1, E = X.end(); I != E; ++I)
- if ((*I < 'a' || *I > 'z') && (*I < 'A' || *I > 'Z') &&
- (*I < '0' || *I > '9') && *I != '_')
- Result += MangleLetter(*I);
+ // If PreserveAsmNames is set, names with asm identifiers are not modified.
+ if (PreserveAsmNames && X[0] == 1)
+ return X;
+
+ if (!UseQuotes) {
+ // If X does not start with (char)1, add the prefix.
+ std::string::const_iterator I = X.begin();
+ if (*I != 1)
+ Result = Prefix;
+ else
+ ++I; // Skip over the marker.
+
+ // Mangle the first letter specially, don't allow numbers.
+ if (*I >= '0' && *I <= '9')
+ Result += MangleLetter(*I++);
+
+ for (std::string::const_iterator E = X.end(); I != E; ++I) {
+ if (!isCharAcceptable(*I))
+ Result += MangleLetter(*I);
+ else
+ Result += *I;
+ }
+ } else {
+ bool NeedsQuotes = false;
+
+ std::string::const_iterator I = X.begin();
+ if (*I == 1)
+ ++I; // Skip over the marker.
+
+ // If the first character is a number, we need quotes.
+ if (*I >= '0' && *I <= '9')
+ NeedsQuotes = true;
+
+ // Do an initial scan of the string, checking to see if we need quotes or
+ // to escape a '"' or not.
+ if (!NeedsQuotes)
+ for (std::string::const_iterator E = X.end(); I != E; ++I)
+ if (!isCharAcceptable(*I)) {
+ NeedsQuotes = true;
+ break;
+ }
+
+ // In the common case, we don't need quotes. Handle this quickly.
+ if (!NeedsQuotes) {
+ if (*X.begin() != 1)
+ return Prefix+X;
+ else
+ return X.substr(1);
+ }
+
+ // Otherwise, construct the string the expensive way.
+ I = X.begin();
+
+ // If X does not start with (char)1, add the prefix.
+ if (*I != 1)
+ Result = Prefix;