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

Proposed by Paul J. Lucas
Status: Merged
Approved by: Paul J. Lucas
Approved revision: 11333
Merged at revision: 11631
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 138 lines (+88/-5)
1 file modified
src/util/utf8_string.h (+88/-5)
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+186402@code.launchpad.net

Commit message

Added more functionality to utf8_string. (Needed for other branches.)

Description of the change

Added more functionality to utf8_string. (Needed for other branches.)

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
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/186402

Progress dashboard at http://jenkins.lambda.nu/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting criteria failed for the following merge proposals:

https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/186402 :
Votes: {'Approve': 1}

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/186402

Stage "CommitZorba" failed.

Check console output at http://jenkins.lambda.nu/job/CommitZorba/186/console to view the results.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/186402

Progress dashboard at http://jenkins.lambda.nu/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/util/utf8_string.h'
2--- src/util/utf8_string.h 2013-04-01 21:01:28 +0000
3+++ src/util/utf8_string.h 2013-09-18 17:42:32 +0000
4@@ -230,6 +230,30 @@
5 ////////// constructors & destructor ////////////////////////////////////////
6
7 /**
8+ * Default contructor wrapped around no string. To wrap around a string at
9+ * a later time, use wrap().
10+ */
11+ utf8_string() : s_( nullptr ), delete_( false ) {
12+ }
13+
14+ /**
15+ * Copy constructor.
16+ *
17+ * @param s The %utf8_string to copy from. If \a s does not have ownership
18+ * of its wrapped string, then this %utf8_string shall wrap the same string;
19+ * if \a s does have ownership, then the wrapped string is duplicated.
20+ */
21+ utf8_string( utf8_string const &s ) {
22+ if ( &s != this && s.s_ ) {
23+ delete_ = s.delete_;
24+ s_ = delete_ ? new StringType( *s.s_ ) : s.s_;
25+ } else {
26+ s_ = nullptr;
27+ delete_ = false;
28+ }
29+ }
30+
31+ /**
32 * Constructs a %utf8_string around the given string.
33 *
34 * @param s The string to wrap. Ownership is not taken.
35@@ -253,7 +277,7 @@
36 /**
37 * Constructs a %utf8_string around a C string.
38 *
39- * @param s The C string.
40+ * @param s The C string to wrap. Ownership is taken.
41 */
42 explicit utf8_string( const_storage_pointer s ) :
43 s_( new StringType( s ) ), delete_( true )
44@@ -264,7 +288,7 @@
45 /**
46 * Constructs a %utf8_string around a C string.
47 *
48- * @param s The C string.
49+ * @param s The C string wrap. Ownership is taken.
50 */
51 explicit utf8_string( storage_pointer s ) :
52 s_( new StringType( s ) ), delete_( true )
53@@ -276,8 +300,59 @@
54 * Destructs this %utf8_string.
55 */
56 ~utf8_string() {
57- if ( delete_ )
58- delete s_;
59+ free();
60+ }
61+
62+ ////////// wrapping /////////////////////////////////////////////////////////
63+
64+ /**
65+ * Wraps this %utf8_string around the given string. (Any previously wrapped
66+ * string is unwrapped first.)
67+ *
68+ * @param s The string to wrap. Ownership is not taken.
69+ * @return Returns a reference to this %utf8_string.
70+ */
71+ utf8_string& wrap( StringType &s ) {
72+ free();
73+ s_ = &s;
74+ delete_ = false;
75+ return *this;
76+ }
77+
78+ /**
79+ * Wraps this %utf8_string around the given string. (Any previously wrapped
80+ * string is unwrapped first.)
81+ *
82+ * @param s The string to wrap. Ownership is taken.
83+ * @return Returns a reference to this %utf8_string.
84+ */
85+ utf8_string& wrap( StringType *s ) {
86+ free();
87+ s_ = s;
88+ delete_ = true;
89+ return *this;
90+ }
91+
92+ /**
93+ * Wraps this %utf8_string around the given C string. (Any previously
94+ * wrapped string is unwrapped first.)
95+ *
96+ * @param s The C string to wrap. Ownership is taken.
97+ * @return Returns a reference to this %utf8_string.
98+ */
99+ utf8_string& wrap( const_storage_pointer s ) {
100+ return wrap( new StringType( s ) );
101+ }
102+
103+ /**
104+ * Wraps this %utf8_string around the given C string. (Any previously
105+ * wrapped string is unwrapped first.)
106+ *
107+ * @param s The C string to wrap. Ownership is taken.
108+ * @return Returns a reference to this %utf8_string.
109+ */
110+ utf8_string& wrap( storage_pointer s ) {
111+ return wrap( new StringType( s ) );
112 }
113
114 ////////// assignment ///////////////////////////////////////////////////////
115@@ -1170,6 +1245,14 @@
116 const_storage_pointer dup( size_type c_n, value_type c );
117
118 /**
119+ * Deletes the wrapped string but only if ownership was taken.
120+ */
121+ void free() {
122+ if ( delete_ )
123+ delete s_;
124+ }
125+
126+ /**
127 * A helper class to convert character position information into its
128 * corresponding byte position information.
129 */
130@@ -1264,7 +1347,7 @@
131 };
132
133 StringType *s_;
134- bool const delete_;
135+ bool delete_;
136 };
137
138 ////////// inline utf8_string members /////////////////////////////////////////

Subscribers

People subscribed via source and target branches