/[pcre]/code/trunk/pcrecpp.cc
ViewVC logotype

Diff of /code/trunk/pcrecpp.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 91 by nigel, Sat Feb 24 21:41:34 2007 UTC
# Line 332  bool RE::Replace(const StringPiece& rewr Line 332  bool RE::Replace(const StringPiece& rewr
332    return true;    return true;
333  }  }
334    
335    // Returns PCRE_NEWLINE_CRLF, PCRE_NEWLINE_CR, or PCRE_NEWLINE_LF.
336    // Note that PCRE_NEWLINE_CRLF is defined to be P_N_CR | P_N_LF.
337    static int NewlineMode(int pcre_options) {
338      // TODO: if we can make it threadsafe, cache this var
339      int newline_mode = 0;
340      /* if (newline_mode) return newline_mode; */  // do this once it's cached
341      if (pcre_options & (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF)) {
342        newline_mode = (pcre_options &
343                        (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF));
344      } else {
345        int newline;
346        pcre_config(PCRE_CONFIG_NEWLINE, &newline);
347        if (newline == 10)
348          newline_mode = PCRE_NEWLINE_LF;
349        else if (newline == 13)
350          newline_mode = PCRE_NEWLINE_CR;
351        else if (newline == 3338)
352          newline_mode = PCRE_NEWLINE_CRLF;
353        else
354          assert("" == "Unexpected return value from pcre_config(NEWLINE)");
355      }
356      return newline_mode;
357    }
358    
359  int RE::GlobalReplace(const StringPiece& rewrite,  int RE::GlobalReplace(const StringPiece& rewrite,
360                        string *str) const {                        string *str) const {
361    int count = 0;    int count = 0;
# Line 350  int RE::GlobalReplace(const StringPiece& Line 374  int RE::GlobalReplace(const StringPiece&
374      if (matchstart == matchend && matchstart == lastend) {      if (matchstart == matchend && matchstart == lastend) {
375        // advance one character if we matched an empty string at the same        // advance one character if we matched an empty string at the same
376        // place as the last match occurred        // place as the last match occurred
377        if (start < static_cast<int>(str->length()))        matchend = start + 1;
378          out.push_back((*str)[start]);        // If the current char is CR and we're in CRLF mode, skip LF too.
379        start++;        // Note it's better to call pcre_fullinfo() than to examine
380          // all_options(), since options_ could have changed bewteen
381          // compile-time and now, but this is simpler and safe enough.
382          if (start+1 < static_cast<int>(str->length()) &&
383              (*str)[start] == '\r' && (*str)[start+1] == '\n' &&
384              NewlineMode(options_.all_options()) == PCRE_NEWLINE_CRLF) {
385            matchend++;
386          }
387          // We also need to advance more than one char if we're in utf8 mode.
388    #ifdef SUPPORT_UTF8
389          if (options_.utf8()) {
390            while (matchend < static_cast<int>(str->length()) &&
391                   ((*str)[matchend] & 0xc0) == 0x80)
392              matchend++;
393          }
394    #endif
395          if (matchend <= static_cast<int>(str->length()))
396            out.append(*str, start, matchend - start);
397          start = matchend;
398      } else {      } else {
399        out.append(*str, start, matchstart - start);        out.append(*str, start, matchstart - start);
400        Rewrite(&out, rewrite, *str, vec, matches);        Rewrite(&out, rewrite, *str, vec, matches);

Legend:
Removed from v.87  
changed lines
  Added in v.91

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12