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

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: 11075
Merged at revision: 11240
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 61 lines (+21/-1)
3 files modified
include/zorba/internal/diagnostic.h (+2/-1)
src/diagnostics/diagnostic.cpp (+13/-0)
src/unit_tests/test_parameters.cpp (+6/-0)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+148590@code.launchpad.net

Commit message

Fixed escaping of \ in parameters.

Description of the change

Fixed escaping of \ in parameters.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2013-02-15T01-42-43.338Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/zorba/internal/diagnostic.h'
2--- include/zorba/internal/diagnostic.h 2013-02-07 03:44:12 +0000
3+++ include/zorba/internal/diagnostic.h 2013-02-15 01:22:24 +0000
4@@ -259,7 +259,7 @@
5 */
6 template<typename T>
7 parameters& operator,( T const &t ) {
8- params_.push_back( ztd::to_string( t ) );
9+ add_param( ztd::to_string( t ) );
10 return *this;
11 }
12
13@@ -330,6 +330,7 @@
14 private:
15 params_type params_;
16
17+ void add_param( value_type const& );
18 value_type lookup_param( size_type i ) const;
19 bool then_else( bool, value_type const&, value_type::size_type*,
20 value_type* ) const;
21
22=== modified file 'src/diagnostics/diagnostic.cpp'
23--- src/diagnostics/diagnostic.cpp 2013-02-07 03:44:12 +0000
24+++ src/diagnostics/diagnostic.cpp 2013-02-15 01:22:24 +0000
25@@ -194,6 +194,19 @@
26 parameters::parameters() {
27 }
28
29+void parameters::add_param( value_type const &s ) {
30+ params_.push_back( s );
31+ value_type &p = params_.back();
32+ //
33+ // We have to escape any literal \ characters in the parameter.
34+ //
35+ for ( value_type::size_type pos = 0;
36+ (pos = p.find( '\\', pos )) != value_type::npos;
37+ pos += 2 ) {
38+ p.replace( pos, 1, "\\\\" );
39+ }
40+}
41+
42 parameters::value_type parameters::lookup_param( size_type i ) const {
43 assert( i >= 1 );
44 assert( i <= 9 );
45
46=== modified file 'src/unit_tests/test_parameters.cpp'
47--- src/unit_tests/test_parameters.cpp 2013-01-23 17:21:10 +0000
48+++ src/unit_tests/test_parameters.cpp 2013-02-15 01:22:24 +0000
49@@ -72,6 +72,12 @@
50 ASSERT_NO_EXCEPTION( p.substitute( &s ) );
51 ASSERT_TRUE( s == "xy" );
52 }
53+ {
54+ string s( "x$1y" );
55+ parameters const p( MAKE_PARAMS( "\\" ) );
56+ ASSERT_NO_EXCEPTION( p.substitute( &s ) );
57+ ASSERT_TRUE( s == "x\\y" );
58+ }
59 }
60
61 static void test_braces() {

Subscribers

People subscribed via source and target branches