/[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 252 by ph10, Mon Sep 17 10:09:22 2007 UTC revision 253 by ph10, Mon Sep 17 10:51:30 2007 UTC
# Line 337  bool RE::Replace(const StringPiece& rewr Line 337  bool RE::Replace(const StringPiece& rewr
337    
338  // Returns PCRE_NEWLINE_CRLF, PCRE_NEWLINE_CR, or PCRE_NEWLINE_LF.  // Returns PCRE_NEWLINE_CRLF, PCRE_NEWLINE_CR, or PCRE_NEWLINE_LF.
339  // Note that PCRE_NEWLINE_CRLF is defined to be P_N_CR | P_N_LF.  // Note that PCRE_NEWLINE_CRLF is defined to be P_N_CR | P_N_LF.
340    // Modified by PH to add PCRE_NEWLINE_ANY and PCRE_NEWLINE_ANYCRLF.
341    
342  static int NewlineMode(int pcre_options) {  static int NewlineMode(int pcre_options) {
343    // TODO: if we can make it threadsafe, cache this var    // TODO: if we can make it threadsafe, cache this var
344    int newline_mode = 0;    int newline_mode = 0;
345    /* if (newline_mode) return newline_mode; */  // do this once it's cached    /* if (newline_mode) return newline_mode; */  // do this once it's cached
346    if (pcre_options & (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF)) {    if (pcre_options & (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|
347                          PCRE_NEWLINE_ANY|PCRE_NEWLINE_ANYCRLF)) {
348      newline_mode = (pcre_options &      newline_mode = (pcre_options &
349                      (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF));                      (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|
350                         PCRE_NEWLINE_ANY|PCRE_NEWLINE_ANYCRLF));
351    } else {    } else {
352      int newline;      int newline;
353      pcre_config(PCRE_CONFIG_NEWLINE, &newline);      pcre_config(PCRE_CONFIG_NEWLINE, &newline);
# Line 353  static int NewlineMode(int pcre_options) Line 357  static int NewlineMode(int pcre_options)
357        newline_mode = PCRE_NEWLINE_CR;        newline_mode = PCRE_NEWLINE_CR;
358      else if (newline == 3338)      else if (newline == 3338)
359        newline_mode = PCRE_NEWLINE_CRLF;        newline_mode = PCRE_NEWLINE_CRLF;
360        else if (newline == -1)
361          newline_mode = PCRE_NEWLINE_ANY;
362        else if (newline == -2)
363          newline_mode = PCRE_NEWLINE_ANYCRLF;
364      else      else
365        assert("" == "Unexpected return value from pcre_config(NEWLINE)");        assert("" == "Unexpected return value from pcre_config(NEWLINE)");
366    }    }
# Line 382  int RE::GlobalReplace(const StringPiece& Line 390  int RE::GlobalReplace(const StringPiece&
390        // Note it's better to call pcre_fullinfo() than to examine        // Note it's better to call pcre_fullinfo() than to examine
391        // all_options(), since options_ could have changed bewteen        // all_options(), since options_ could have changed bewteen
392        // compile-time and now, but this is simpler and safe enough.        // compile-time and now, but this is simpler and safe enough.
393          // Modified by PH to add ANY and ANYCRLF.
394        if (start+1 < static_cast<int>(str->length()) &&        if (start+1 < static_cast<int>(str->length()) &&
395            (*str)[start] == '\r' && (*str)[start+1] == '\n' &&            (*str)[start] == '\r' && (*str)[start+1] == '\n' &&
396            NewlineMode(options_.all_options()) == PCRE_NEWLINE_CRLF) {            (NewlineMode(options_.all_options()) == PCRE_NEWLINE_CRLF ||
397               NewlineMode(options_.all_options()) == PCRE_NEWLINE_ANY ||
398               NewlineMode(options_.all_options()) == PCRE_NEWLINE_ANYCRLF)
399              ) {
400          matchend++;          matchend++;
401        }        }
402        // We also need to advance more than one char if we're in utf8 mode.        // We also need to advance more than one char if we're in utf8 mode.

Legend:
Removed from v.252  
changed lines
  Added in v.253

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12