~ubuntu-branches/debian/sid/gsmartcontrol/sid

« back to all changes in this revision

Viewing changes to src/hz/ascii.h

  • Committer: Package Import Robot
  • Author(s): Giuseppe Iuculano
  • Date: 2013-05-31 11:41:52 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130531114152-5ljhkuswwpt4kdwo
Tags: 0.8.7-1
* [314881d] Updated debian/watch
* [18ebada] Imported Upstream version 0.8.7
* [c2a1f1b] debian/rules: Provide build-arch and build-indep
* [d3036a4] Enabled Hardening Options
* [2edfb87] Refreshed patches and removed patches apllied upstream
* [ac3b953] Bump to standard versions 3.9.4
* [292c276] Remove quilt from depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 Copyright:
3
3
      (C) 1992, 1993  The Regents of the University of California
4
4
 License: See LICENSE_bsd-ucb.txt file
5
 
      (C) 2008 - 2011  Alexander Shaduri <ashaduri 'at' gmail.com>
 
5
      (C) 2008 - 2012  Alexander Shaduri <ashaduri 'at' gmail.com>
6
6
 License: See LICENSE_zlib.txt file
7
7
***************************************************************************/
 
8
/// \file
 
9
/// \author The Regents of the University of California
 
10
/// \author Alexander Shaduri
 
11
/// \ingroup hz
 
12
/// \weakgroup hz
 
13
/// @{
8
14
 
9
15
#ifndef HZ_ASCII_H
10
16
#define HZ_ASCII_H
12
18
#include "hz_config.h"  // feature macros
13
19
 
14
20
 
15
 
// Part of this file (specifically, ascii_strtoi() implementation)
16
 
// is derived from FreeBSD's strtol() and friends.
 
21
/// \file
 
22
/// Part of this file (specifically, ascii_strtoi() implementation)
 
23
/// is derived from FreeBSD's strtol() and friends.
17
24
 
18
25
// The original FreeBSD copyright header follows:
19
26
/*-
79
86
 
80
87
 
81
88
 
82
 
// Implementation of std::isspace().
83
 
// This function always behaves like the standard function
84
 
// does in Classic locale.
 
89
/// Implementation of std::isspace().
 
90
/// This function always behaves like the standard function
 
91
/// does in Classic locale (regardless of current locale).
85
92
inline bool ascii_isspace(char c)
86
93
{
87
94
        return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v');
89
96
 
90
97
 
91
98
 
92
 
// Implementation of std::strtoX() for every native integral type:
93
 
// char (numerical value), wchar_t (numerical value),
94
 
// int, short, long, long long, plus their signed/unsigned variants.
95
 
// This function always behaves like the standard functions do
96
 
// in Classic locale.
 
99
/// Implementation of std::strtoX() functions for every native integral type:
 
100
/// char (numerical value), wchar_t (numerical value),
 
101
/// int, short, long, long long, plus their signed/unsigned variants.
 
102
/// This function always behaves like the standard functions do
 
103
/// in Classic locale.
97
104
template<typename T> inline
98
105
T ascii_strtoi(const char* nptr, char** endptr, int base)
99
106
{
232
239
 
233
240
        // proxy functions for system strtod family.
234
241
 
235
 
        // we use struct because the errors are easier on the user this way.
 
242
        /// We use struct because the errors are easier on the user this way.
236
243
        template<typename T>
237
244
        struct ascii_strtof_impl { };
238
245
 
239
246
 
 
247
        /// Specialization
240
248
        template<>
241
249
        struct ascii_strtof_impl<double> {
242
250
                static double func(const char* nptr, char** endptr)
248
256
 
249
257
        // Note: strtold() and strtof() are C99 / _XOPEN_SOURCE >= 600.
250
258
 
 
259
        /// Specialization
251
260
        template<>
252
261
        struct ascii_strtof_impl<float> {
253
262
                static float func(const char* nptr, char** endptr)
284
293
        };
285
294
 
286
295
 
 
296
        /// Specialization
287
297
        template<>
288
298
        struct ascii_strtof_impl<long double> {
289
299
                static long double func(const char* nptr, char** endptr)
328
338
// on overflow, +/-HUGE_VAL[L|F] is returned, and errno is set to ERANGE.
329
339
// on underflow, 0 is returned and errno is set to ERANGE.
330
340
 
331
 
// A unified strtod/strtof/strtold.
332
 
// This function always behaves like the standard functions do
333
 
// in Classic locale.
 
341
/// Implementation of strtod/strtof/strtold for any floating-point type.
 
342
/// This function always behaves like the standard functions do
 
343
/// in Classic locale.
334
344
template<typename T> inline
335
345
T ascii_strtof(const char* nptr, char** endptr)
336
346
{
472
482
 
473
483
namespace {
474
484
 
 
485
        /// Helper struct to choose the correct implementation
475
486
        template<bool IsInt, bool IsFloat>
476
487
        struct ascii_strton_impl { };
477
488
 
 
489
        /// Specialization
478
490
        template<bool IsInt>
479
491
        struct ascii_strton_impl<IsInt, true> {
480
492
                template<typename T> inline
484
496
                }
485
497
        };
486
498
 
 
499
        /// Specialization
487
500
        template<bool IsFloat>
488
501
        struct ascii_strton_impl<true, IsFloat> {
489
502
                template<typename T> inline
497
510
 
498
511
 
499
512
 
500
 
// Note: Parameter "base" is ignored for floating point types.
 
513
/// Create any number (integral or floating point) from a string.
 
514
/// Note: Parameter "base" is ignored for floating point types.
501
515
template<typename T> inline
502
516
T ascii_strton(const char* nptr, char** endptr, int base = 0)
503
517
{
514
528
 
515
529
 
516
530
#endif
 
531
 
 
532
/// @}