← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~paul-lucas/zorba/pjl-misc into lp:zorba

 

Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
Fixed escaping of \ in parameters.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/148590

Fixed escaping of \ in parameters.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/148590
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/internal/diagnostic.h'
--- include/zorba/internal/diagnostic.h	2013-02-07 03:44:12 +0000
+++ include/zorba/internal/diagnostic.h	2013-02-15 01:22:24 +0000
@@ -259,7 +259,7 @@
    */
   template<typename T>
   parameters& operator,( T const &t ) {
-    params_.push_back( ztd::to_string( t ) );
+    add_param( ztd::to_string( t ) );
     return *this;
   }
 
@@ -330,6 +330,7 @@
 private:
   params_type params_;
 
+  void add_param( value_type const& );
   value_type lookup_param( size_type i ) const;
   bool then_else( bool, value_type const&, value_type::size_type*,
                   value_type* ) const;

=== modified file 'src/diagnostics/diagnostic.cpp'
--- src/diagnostics/diagnostic.cpp	2013-02-07 03:44:12 +0000
+++ src/diagnostics/diagnostic.cpp	2013-02-15 01:22:24 +0000
@@ -194,6 +194,19 @@
 parameters::parameters() {
 }
 
+void parameters::add_param( value_type const &s ) {
+  params_.push_back( s );
+  value_type &p = params_.back();
+  //
+  // We have to escape any literal \ characters in the parameter.
+  //
+  for ( value_type::size_type pos = 0;
+        (pos = p.find( '\\', pos )) != value_type::npos;
+        pos += 2 ) {
+    p.replace( pos, 1, "\\\\" );
+  }
+}
+
 parameters::value_type parameters::lookup_param( size_type i ) const {
   assert( i >= 1 );
   assert( i <= 9 );

=== modified file 'src/unit_tests/test_parameters.cpp'
--- src/unit_tests/test_parameters.cpp	2013-01-23 17:21:10 +0000
+++ src/unit_tests/test_parameters.cpp	2013-02-15 01:22:24 +0000
@@ -72,6 +72,12 @@
     ASSERT_NO_EXCEPTION( p.substitute( &s ) );
     ASSERT_TRUE( s == "xy" );
   }
+  {
+    string s( "x$1y" );
+    parameters const p( MAKE_PARAMS( "\\" ) );
+    ASSERT_NO_EXCEPTION( p.substitute( &s ) );
+    ASSERT_TRUE( s == "x\\y" );
+  }
 }
 
 static void test_braces() {


Follow ups