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

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: 11101
Merged at revision: 11270
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 519 lines (+150/-101)
6 files modified
src/runtime/full_text/thesauri/iso2788.cpp (+1/-1)
src/util/file.cpp (+1/-1)
src/util/fs_util.cpp (+11/-6)
src/util/fs_util.h (+15/-5)
src/util/string_util.cpp (+70/-53)
src/util/string_util.h (+52/-35)
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+151674@code.launchpad.net

Commit message

Added "follow_symlink" to fs::get_type().
Added atoull( char const *buf, char const *end, char const **last );

Description of the change

Added "follow_symlink" to fs::get_type().
Added atoull( char const *buf, char const *end, char const **last );

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-03-05T04-29-43.078Z 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 'src/runtime/full_text/thesauri/iso2788.cpp'
2--- src/runtime/full_text/thesauri/iso2788.cpp 2013-02-07 17:24:36 +0000
3+++ src/runtime/full_text/thesauri/iso2788.cpp 2013-03-05 02:25:27 +0000
4@@ -15,7 +15,7 @@
5 */
6 #include "stdafx.h"
7
8-#include <algorithm> /* for lower_bound() */
9+#include <algorithm> /* for equal_range() */
10 #include <cstring>
11
12 #include "util/less.h"
13
14=== modified file 'src/util/file.cpp'
15--- src/util/file.cpp 2013-02-07 17:24:36 +0000
16+++ src/util/file.cpp 2013-03-05 02:25:27 +0000
17@@ -216,7 +216,7 @@
18
19 void file::do_stat() {
20 #ifdef ZORBA_WITH_FILE_ACCESS
21- fs::size_type fs_size;
22+ fs::size_type fs_size = 0;
23 switch ( fs::get_type( c_str(), &fs_size ) ) {
24 case fs::non_existent: type = type_non_existent; break;
25 case fs::directory : type = type_directory; break;
26
27=== modified file 'src/util/fs_util.cpp'
28--- src/util/fs_util.cpp 2013-02-07 17:24:36 +0000
29+++ src/util/fs_util.cpp 2013-03-05 02:25:27 +0000
30@@ -275,20 +275,25 @@
31
32 #endif /* ZORBA_WITH_FILE_ACCESS */
33
34-type get_type( char const *path, size_type *size ) {
35+type get_type( char const *path, bool follow_symlink, size_type *size ) {
36 #ifndef WIN32
37 struct stat st_buf;
38- if ( ::stat( path, &st_buf ) == -1 ) {
39+ int const status = follow_symlink ?
40+ ::stat( path, &st_buf ) : ::lstat( path, &st_buf );
41+ if ( status == -1 ) {
42 if ( errno == ENOENT )
43 return non_existent;
44- throw ZORBA_IO_EXCEPTION( "stat()", path );
45+ throw ZORBA_IO_EXCEPTION( follow_symlink ? "stat()" : "lstat()", path );
46 }
47 if ( S_ISDIR( st_buf.st_mode ) )
48 return directory;
49- if ( size )
50- *size = st_buf.st_size;
51- if ( S_ISREG( st_buf.st_mode ) )
52+ if ( S_ISLNK( st_buf.st_mode ) )
53+ return link;
54+ if ( S_ISREG( st_buf.st_mode ) ) {
55+ if ( size )
56+ *size = st_buf.st_size;
57 return file;
58+ }
59 return other;
60 #else
61 WCHAR wpath[ MAX_PATH ];
62
63=== modified file 'src/util/fs_util.h'
64--- src/util/fs_util.h 2013-02-07 17:24:36 +0000
65+++ src/util/fs_util.h 2013-03-05 02:25:27 +0000
66@@ -500,27 +500,37 @@
67 * Gets the type of the given file.
68 *
69 * @param path The full path to check.
70+ * @param follow_symlink If \c true follows symbolic links.
71 * @param size A pointer to a receive the size of the file in bytes. The size
72 * is set only if it's not \c nullptr and the file's type is \c file.
73- * @return Returns said type.
74+ * @return If \a path refers to a symbolic link and \a follow_symlink is
75+ * \c true, the type returned is of that to which the link refers; if \a path
76+ * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
77+ * \a path does not refer to a symbolic link, returns the type of \a path.
78 */
79-type get_type( char const *path, size_type *size = nullptr );
80+type get_type( char const *path, bool follow_symlink = true,
81+ size_type *size = nullptr );
82
83 /**
84 * Gets the type of the given file.
85 *
86 * @tparam PathStringType The \a path string type.
87 * @param path The full path to check.
88+ * @param follow_symlink If \c true follows symbolic links.
89 * @param size A pointer to a receive the size of the file in bytes. The size
90 * is set only if it's not \c nullptr and the file's type is \c file.
91- * @return Returns said type.
92+ * @return If \a path refers to a symbolic link and \a follow_symlink is
93+ * \c true, the type returned is of that to which the link refers; if \a path
94+ * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
95+ * \a path does not refer to a symbolic link, returns the type of \a path.
96 */
97 template<class PathStringType> inline
98 typename std::enable_if<ztd::has_c_str<PathStringType,
99 char const* (PathStringType::*)() const>::value,
100 type>::type
101-get_type( PathStringType const &path, size_type *size = nullptr ) {
102- return get_type( path.c_str(), size );
103+get_type( PathStringType const &path, bool follow_symlink = true,
104+ size_type *size = nullptr ) {
105+ return get_type( path.c_str(), follow_symlink, size );
106 }
107
108 /**
109
110=== modified file 'src/util/string_util.cpp'
111--- src/util/string_util.cpp 2013-02-07 17:24:36 +0000
112+++ src/util/string_util.cpp 2013-03-05 02:25:27 +0000
113@@ -28,8 +28,8 @@
114
115 // Windows doesn't have these functions -- add them ourselves.
116
117- static float strtof( char const *s, char **end ) {
118- double const result = std::strtod( s, end );
119+ static float strtof( char const *s, char **last ) {
120+ double const result = std::strtod( s, last );
121 if ( !errno ) {
122 if ( result < std::numeric_limits<float>::min() ||
123 result > std::numeric_limits<float>::max() )
124@@ -38,12 +38,12 @@
125 return static_cast<float>( result );
126 }
127
128- inline long long strtoll( char const *s, char **end, int base ) {
129- return ::_strtoi64( s, end, base );
130+ inline long long strtoll( char const *s, char **last, int base ) {
131+ return ::_strtoi64( s, last, base );
132 }
133
134- inline unsigned long long strtoull( char const *s, char **end, int base ) {
135- return ::_strtoui64( s, end, base );
136+ inline unsigned long long strtoull( char const *s, char **last, int base ) {
137+ return ::_strtoui64( s, last, base );
138 }
139
140 } // namespace std
141@@ -56,43 +56,39 @@
142
143 ///////////////////////////////////////////////////////////////////////////////
144
145-static void no_digits( char const *buf ) {
146- throw std::invalid_argument( BUILD_STRING( '"', buf, "\": no digits" ) );
147-}
148-
149-static void too_big_or_small( char const *buf, char const *end ) {
150- zstring const s( buf, end );
151+static void too_big_or_small( char const *buf, char const *last ) {
152+ zstring const s( buf, last );
153 throw std::range_error( BUILD_STRING( '"', s, "\": number too big/small" ) );
154 }
155
156-inline void check_errno( char const *buf, char const *end ) {
157+inline void check_errno( char const *buf, char const *last ) {
158 if ( errno == ERANGE )
159- too_big_or_small( buf, end );
160+ too_big_or_small( buf, last );
161 }
162
163-static void check_trailing_chars_impl( char const *end ) {
164- for ( ; *end; ++end ) // remaining characters, if any, ...
165- if ( !ascii::is_space( *end ) ) // ... may only be whitespace
166+static void check_trailing_chars_impl( char const *last ) {
167+ for ( ; *last; ++last ) // remaining characters, if any, ...
168+ if ( !ascii::is_space( *last ) ) // ... may only be whitespace
169 throw std::invalid_argument(
170- BUILD_STRING( '\'', *end, "': invalid character" )
171+ BUILD_STRING( '\'', *last, "': invalid character" )
172 );
173 }
174
175-inline void check_parse_number( char const *buf, char const *end,
176+inline void check_parse_number( char const *buf, char const *last,
177 bool check_trailing_chars ) {
178- if ( end == buf )
179- no_digits( buf );
180+ if ( last == buf )
181+ throw std::invalid_argument( BUILD_STRING( '"', buf, "\": no digits" ) );
182 if ( check_trailing_chars )
183- check_trailing_chars_impl( end );
184+ check_trailing_chars_impl( last );
185 }
186
187 class aton_context {
188 public:
189- aton_context( char const **&end ) {
190- if ( end ) {
191+ aton_context( char const **&last ) {
192+ if ( last ) {
193 check_trailing_chars_ = false;
194 } else {
195- end = &end_;
196+ last = &last_;
197 check_trailing_chars_ = true;
198 }
199 errno = 0;
200@@ -102,44 +98,44 @@
201 }
202 private:
203 bool check_trailing_chars_;
204- char const *end_;
205+ char const *last_;
206 };
207
208 ///////////////////////////////////////////////////////////////////////////////
209
210-double atod( char const *buf, char const **end ) {
211- aton_context const ctx( end );
212- double const result = std::strtod( buf, (char**)end );
213- check_parse_number( buf, *end, ctx.check_trailing_chars() );
214- return result;
215-}
216-
217-float atof( char const *buf, char const **end ) {
218- aton_context const ctx( end );
219- float const result = std::strtof( buf, (char**)end );
220- check_parse_number( buf, *end, ctx.check_trailing_chars() );
221- return result;
222-}
223-
224-long long atoll( char const *buf, char const **end ) {
225- aton_context const ctx( end );
226- long long const result = std::strtoll( buf, (char**)end, 10 );
227- check_errno( buf, *end );
228- check_parse_number( buf, *end, ctx.check_trailing_chars() );
229- return result;
230-}
231-
232-unsigned long long atoull( char const *buf, char const **end ) {
233- aton_context const ctx( end );
234+double atod( char const *buf, char const **last ) {
235+ aton_context const ctx( last );
236+ double const result = std::strtod( buf, (char**)last );
237+ check_parse_number( buf, *last, ctx.check_trailing_chars() );
238+ return result;
239+}
240+
241+float atof( char const *buf, char const **last ) {
242+ aton_context const ctx( last );
243+ float const result = std::strtof( buf, (char**)last );
244+ check_parse_number( buf, *last, ctx.check_trailing_chars() );
245+ return result;
246+}
247+
248+long long atoll( char const *buf, char const **last ) {
249+ aton_context const ctx( last );
250+ long long const result = std::strtoll( buf, (char**)last, 10 );
251+ check_errno( buf, *last );
252+ check_parse_number( buf, *last, ctx.check_trailing_chars() );
253+ return result;
254+}
255+
256+unsigned long long atoull( char const *buf, char const **last ) {
257+ aton_context const ctx( last );
258 //
259 // We have to check for '-' ourselves since strtoull(3) allows it (oddly).
260 //
261 buf = ascii::trim_start_whitespace( buf );
262 bool const minus = *buf == '-';
263
264- unsigned long long const result = std::strtoull( buf, (char**)end, 10 );
265- check_errno( buf, *end );
266- check_parse_number( buf, *end, ctx.check_trailing_chars() );
267+ unsigned long long const result = std::strtoull( buf, (char**)last, 10 );
268+ check_errno( buf, *last );
269+ check_parse_number( buf, *last, ctx.check_trailing_chars() );
270
271 if ( minus && result ) {
272 //
273@@ -153,6 +149,27 @@
274 return result;
275 }
276
277+unsigned long long atoull( char const *buf, char const *end,
278+ char const **last ) {
279+ aton_context const ctx( last );
280+ unsigned long long n = 0;
281+ char const *s = buf;
282+
283+ for ( ; s < end && ascii::is_space( *s ); ++s )
284+ ;
285+ for ( ; s < end && ascii::is_digit( *s ); ++s ) {
286+ unsigned long long const n_prev = n;
287+ n = n * 10 + *s - '0';
288+ if ( n < n_prev ) {
289+ errno = ERANGE;
290+ too_big_or_small( buf, end );
291+ }
292+ }
293+ *last = s;
294+ check_parse_number( buf, *last, ctx.check_trailing_chars() );
295+ return n;
296+}
297+
298 char* itoa( long long n, char *buf ) {
299 //
300 // This implementation is much faster than using sprintf(3).
301
302=== modified file 'src/util/string_util.h'
303--- src/util/string_util.h 2013-02-07 17:24:36 +0000
304+++ src/util/string_util.h 2013-03-05 02:25:27 +0000
305@@ -410,7 +410,7 @@
306 *
307 * @param buf The null-terminated C string to parse. Leading and trailing
308 * whitespace is ignored.
309- * @param end If not \c null, this is set to point to the character after the
310+ * @param last If not \c null, this is set to point to the character after the
311 * last numeric character parsed; if \c null, characters past the last numeric
312 * character may only be whitespace.
313 * @return Returns the \c double value.
314@@ -418,14 +418,14 @@
315 * leading/trailing whitespace, or contains no digits at all.
316 * @throws range_error if the number overflows/underflows.
317 */
318-double atod( char const *buf, char const **end = nullptr );
319+double atod( char const *buf, char const **last = nullptr );
320
321 /**
322 * Parses the given string for a \c float.
323 *
324 * @param buf The null-terminated C string to parse. Leading and trailing
325 * whitespace is ignored.
326- * @param end If not \c null, this is set to point to the character after the
327+ * @param last If not \c null, this is set to point to the character after the
328 * last numeric character parsed; if \c null, characters past the last numeric
329 * character may only be whitespace.
330 * @return Returns the \c float value.
331@@ -433,14 +433,14 @@
332 * leading/trailing whitespace, or contains no digits at all.
333 * @throws range_error if the number overflows/underflows.
334 */
335-float atof( char const *buf, char const **end = nullptr );
336+float atof( char const *buf, char const **last = nullptr );
337
338 /**
339- * Parses the given string for a <code>long lomg</code>.
340+ * Parses the given string for a <code>long long</code>.
341 *
342 * @param buf The null-terminated C string to parse. Leading and trailing
343 * whitespace is ignored.
344- * @param end If not \c null, this is set to point to the character after the
345+ * @param last If not \c null, this is set to point to the character after the
346 * last numeric character parsed; if \c null, characters past the last numeric
347 * character may only be whitespace.
348 * @return Returns the <code>long long</code> value.
349@@ -448,22 +448,39 @@
350 * leading/trailing whitespace, or contains no digits at all.
351 * @throws range_error if the number overflows/underflows.
352 */
353-long long atoll( char const *buf, char const **end = nullptr );
354+long long atoll( char const *buf, char const **last = nullptr );
355
356 /**
357- * Parses the given string for an <code>unsigned long lomg</code>.
358+ * Parses the given string for an <code>unsigned long long</code>.
359 *
360 * @param buf The null-terminated C string to parse. Leading and trailing
361 * whitespace is ignored.
362- * @param end If not \c null, this is set to point to the character after the
363- * last numeric character parsed; if \c null, characters past the last numeric
364- * character may only be whitespace.
365- * @return Returns the <code>unsigned long long</code> value.
366- * @throws invalid_argument if \a buf contains characters other than digits or
367- * leading/trailing whitespace, or contains no digits at all.
368- * @throws range_error if the number overflows/underflows.
369- */
370-unsigned long long atoull( char const *buf, char const **end = nullptr );
371+ * @param last If not \c null, this is set to point to the character after the
372+ * last numeric character parsed; if \c null, characters past the last numeric
373+ * character may only be whitespace.
374+ * @return Returns the <code>unsigned long long</code> value.
375+ * @throws invalid_argument if \a buf contains characters other than digits or
376+ * leading/trailing whitespace, or contains no digits at all.
377+ * @throws range_error if the number overflows.
378+ */
379+unsigned long long atoull( char const *buf, char const **last = nullptr );
380+
381+/**
382+ * Parses the given string for an <code>unsigned long long</code>.
383+ *
384+ * @param buf The C string to parse; it need not be null-terminated. Leading
385+ * and trailing whitespace is ignored.
386+ * @param end A pointer to one past the last character to parse.
387+ * @param last If not \c null, this is set to point to the character after the
388+ * last numeric character parsed; if \c null, characters past the last numeric
389+ * character may only be whitespace.
390+ * @return Returns the <code>unsigned long long</code> value.
391+ * @throws invalid_argument if \a buf contains characters other than digits or
392+ * leading/trailing whitespace, or contains no digits at all.
393+ * @throws range_error if the number overflows.
394+ */
395+unsigned long long atoull( char const *buf, char const *end,
396+ char const **last );
397
398 /**
399 * Parses the given string for a C++ signed integral type.
400@@ -471,7 +488,7 @@
401 * @tparam IntegralType The C++ signed integral type to parse for.
402 * @param buf The null-terminated C string to parse. Leading and trailing
403 * whitespace is ignored.
404- * @param end If not \c null, this is set to point to the character after the
405+ * @param last If not \c null, this is set to point to the character after the
406 * last numeric character parsed; if \c null, characters past the last numeric
407 * character may only be whitespace.
408 * @return Returns the \c IntegralType value.
409@@ -488,8 +505,8 @@
410 typename std::enable_if<ZORBA_TR1_NS::is_integral<IntegralType>::value
411 && ZORBA_TR1_NS::is_signed<IntegralType>::value,
412 IntegralType>::type
413-aton( char const *buf, char const **end = nullptr ) {
414- long long const result = atoll( buf, end );
415+aton( char const *buf, char const **last = nullptr ) {
416+ long long const result = atoll( buf, last );
417 if ( result < std::numeric_limits<IntegralType>::min() ||
418 result > std::numeric_limits<IntegralType>::max() )
419 throw std::range_error(
420@@ -506,7 +523,7 @@
421 * whitespace is ignored.
422 * @param low The lower acceptable bound.
423 * @param high the higher acceptable bound.
424- * @param end If not \c null, this is set to point to the character after the
425+ * @param last If not \c null, this is set to point to the character after the
426 * last numeric character parsed; if \c null, characters past the last numeric
427 * character may only be whitespace.
428 * @return Returns the \c IntegralType value.
429@@ -524,8 +541,8 @@
430 && ZORBA_TR1_NS::is_signed<IntegralType>::value,
431 IntegralType>::type
432 aton( char const *buf, IntegralType low, IntegralType high,
433- char const **end = nullptr ) {
434- long long const result = atoll( buf, end );
435+ char const **last = nullptr ) {
436+ long long const result = atoll( buf, last );
437 if ( result < low || result > high )
438 throw std::range_error(
439 BUILD_STRING(
440@@ -541,7 +558,7 @@
441 * @tparam IntegralType The C++ unsigned integral type to parse for.
442 * @param buf The null-terminated C string to parse. Leading and trailing
443 * whitespace is ignored.
444- * @param end If not \c null, this is set to point to the character after the
445+ * @param last If not \c null, this is set to point to the character after the
446 * last numeric character parsed; if \c null, characters past the last numeric
447 * character may only be whitespace.
448 * @return Returns the \c IntegralType value.
449@@ -552,8 +569,8 @@
450 template<typename IntegralType> inline
451 typename std::enable_if<ZORBA_TR1_NS::is_unsigned<IntegralType>::value,
452 IntegralType>::type
453-aton( char const *buf, char const **end = nullptr ) {
454- unsigned long long const result = atoull( buf, end );
455+aton( char const *buf, char const **last = nullptr ) {
456+ unsigned long long const result = atoull( buf, last );
457 if ( result > std::numeric_limits<IntegralType>::max() )
458 throw std::range_error( BUILD_STRING( '"', result, "\": number too big" ) );
459 return static_cast<IntegralType>( result );
460@@ -567,7 +584,7 @@
461 * whitespace is ignored.
462 * @param low The lower acceptable bound.
463 * @param high the higher acceptable bound.
464- * @param end If not \c null, this is set to point to the character after the
465+ * @param last If not \c null, this is set to point to the character after the
466 * last numeric character parsed; if \c null, characters past the last numeric
467 * character may only be whitespace.
468 * @return Returns the \c IntegralType value.
469@@ -579,8 +596,8 @@
470 typename std::enable_if<ZORBA_TR1_NS::is_unsigned<IntegralType>::value,
471 IntegralType>::type
472 aton( char const *buf, IntegralType low, IntegralType high,
473- char const **end = nullptr ) {
474- unsigned long long const result = atoull( buf, end );
475+ char const **last = nullptr ) {
476+ unsigned long long const result = atoull( buf, last );
477 if ( result < low || result > high )
478 throw std::range_error(
479 BUILD_STRING(
480@@ -595,7 +612,7 @@
481 *
482 * @param buf The null-terminated C string to parse. Leading and trailing
483 * whitespace is ignored.
484- * @param end If not \c null, this is set to point to the character after the
485+ * @param last If not \c null, this is set to point to the character after the
486 * last numeric character parsed; if \c null, characters past the last numeric
487 * character may only be whitespace.
488 * @return Returns the \c double value.
489@@ -607,8 +624,8 @@
490 template<typename NumericType> inline
491 typename std::enable_if<ZORBA_TR1_NS::is_same<NumericType,double>::value,
492 NumericType>::type
493-aton( char const *buf, char const **end = nullptr ) {
494- return atod( buf, end );
495+aton( char const *buf, char const **last = nullptr ) {
496+ return atod( buf, last );
497 }
498
499 /**
500@@ -616,7 +633,7 @@
501 *
502 * @param buf The null-terminated C string to parse. Leading and trailing
503 * whitespace is ignored.
504- * @param end If not \c null, this is set to point to the character after the
505+ * @param last If not \c null, this is set to point to the character after the
506 * last numeric character parsed; if \c null, characters past the last numeric
507 * character may only be whitespace.
508 * @return Returns the \c float value.
509@@ -628,8 +645,8 @@
510 template<typename NumericType> inline
511 typename std::enable_if<ZORBA_TR1_NS::is_same<NumericType,float>::value,
512 NumericType>::type
513-aton( char const *buf, char const **end = nullptr ) {
514- return atof( buf, end );
515+aton( char const *buf, char const **last = nullptr ) {
516+ return atof( buf, last );
517 }
518
519 ////////// To-string conversion ////////////////////////////////////////////////

Subscribers

People subscribed via source and target branches