Ignore:
Timestamp:
Mar 8, 2011, 1:56:48 PM (13 years ago)
Author:
rybkin
Message:

See C.L. 444

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/source/cmt_symbol.cxx

    r550 r561  
    30613061
    30623062//-------------------------------------------------------------
    3063 //  Quote separators (spaces and tabs) with double quotes,
    3064 //  double quotes with single quotes,
    3065 //  single quotes with double quotes in text.
    3066 //  Note: quotes preceded by backslash (i.e., \" or \') are NOT quoted
    3067 //  (considered escaped)
    3068 //-------------------------------------------------------------
    3069 static cmt_string quote (const cmt_string& text,
    3070                          const cmt_string& separators)
    3071 {
    3072   //cerr << "quote: `" << text << "'" << endl;
    3073   cmt_string result;
    3074   if (text.size () == 0) return result;
    3075 
    3076   int allocated = 3 * text.size (); // if EACH character of text quoted with " or '
    3077   char* const buffer = (char*) malloc (allocated + 1);
    3078   char* b (buffer);
    3079 
    3080   //  char* const beg (buffer);
    3081   const char* p = text.c_str ();
    3082   const char* const text_c (p);
    3083   //  const char* const beg_t (p);
    3084   //  cerr << "quote: p = `" << p << "'" << endl;
    3085 
    3086   while (*p)
    3087     //  while (*p != '\0')
    3088     {
    3089       size_t l_nonsep = strcspn (p, separators.c_str ());
    3090       //cerr << "quote: l_nonsep = " << l_nonsep << " *p = '" << *p << "'" << endl;
    3091       while (l_nonsep--)
    3092         {
    3093           if (*p == '\"' &&
    3094               (p > text_c && *(p - 1) != '\\' || p == text_c))
    3095             { // quote " with '
    3096               *b++ = '\'';
    3097               *b++ = *p++;
    3098               *b++ = '\'';
    3099             }
    3100           else if (*p == '\'' &&
    3101                    (p > text_c && *(p - 1) != '\\' || p == text_c))
    3102             { // quote ' with "
    3103               *b++ = '\"';
    3104               *b++ = *p++;
    3105               *b++ = '\"';
    3106             }
    3107           else
    3108             { // simply copy
    3109               *b++ = *p++;
    3110             }
    3111         }
    3112       size_t l_sep = strspn (p, separators.c_str ());
    3113       //cerr << "quote: l_sep = " << l_sep << " *p = '" << *p << "'" << endl;
    3114       if (l_sep)
    3115         { // quote separators with "
    3116           // place quote before all backslashes preceding separators, if any
    3117           char* r = b;
    3118           while (r > buffer && *(r - 1) == '\\')
    3119             r--;
    3120           if (r == b)
    3121             *b++ = '\"';
    3122           else
    3123             *r = '\"', *b++ = '\\';
    3124           while (l_sep--)
    3125             *b++ = *p++;
    3126           *b++ = '\"';
    3127         }
    3128     }
    3129   *b = '\0';
    3130   result = buffer;
    3131   free (buffer);
    3132   return result;
    3133 }
    3134 
    3135 //-------------------------------------------------------------
    31363063int SymbolValueList::print (const Symbol& symbol,
    31373064                            const SymbolValue& value,
     
    33113238    }
    33123239
    3313   cout << " " << quote (value.text, " \t");
     3240  cout << " " << CmtSystem::quote (value.text, " \t");
    33143241  //  cout << "'" << value.text << "'";
    33153242         
Note: See TracChangeset for help on using the changeset viewer.