Warning, file /sdk/codevis/thirdparty/soci/include/private/soci-dtocstr.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // Copyright (C) 2014 Vadim Zeitlin.
0003 // Distributed under the Boost Software License, Version 1.0.
0004 // (See accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef SOCI_PRIVATE_SOCI_DTOCSTR_H_INCLUDED
0009 #define SOCI_PRIVATE_SOCI_DTOCSTR_H_INCLUDED
0010 
0011 #include "soci/soci-platform.h"
0012 #include "soci/error.h"
0013 
0014 #include <stdlib.h>
0015 #include <stdio.h>
0016 
0017 namespace soci
0018 {
0019 
0020 namespace details
0021 {
0022 
0023 // Locale-independent, i.e. always using "C" locale, function for converting
0024 // floating point number to string.
0025 //
0026 // The resulting string will contain the floating point number in "C" locale,
0027 // i.e. will always use point as decimal separator independently of the current
0028 // locale.
0029 inline
0030 std::string double_to_cstring(double d)
0031 {
0032     // See comments in cstring_to_double() in soci-cstrtod.h, we're dealing
0033     // with the same issues here.
0034 
0035     static size_t const bufSize = 32;
0036     char buf[bufSize];
0037     snprintf(buf, bufSize, "%.20g", d);
0038 
0039     // Replace any commas which can be used as decimal separator with points.
0040     for (char* p = buf; *p != '\0'; p++ )
0041     {
0042         if (*p == ',')
0043         {
0044             *p = '.';
0045 
0046             // There can be at most one comma in this string anyhow.
0047             break;
0048         }
0049     }
0050 
0051     return buf;
0052 }
0053 
0054 } // namespace details
0055 
0056 } // namespace soci
0057 
0058 #endif // SOCI_PRIVATE_SOCI_DTOCSTR_H_INCLUDED