| 1 | /* melder_ftoa.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2008,2010-2012,2014-2026 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "melder.h"cxx . . $ `<file>/melder/melder.h`/ |
| 20 | |
| 21 | /********** NUMBER TO STRING CONVERSION **********/ |
| 22 | |
| 23 | inline constexpr int NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS. = 32; // = maximum number of arguments to a function call |
| 24 | inline constexpr int extraRoomcxx . . $ extraRoom. = 2; |
| 25 | inline constexpr int MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH. = 1200; // = sign + 324 zeroes + point + 60 precision + 6 "·10^^^" + sign + 3, times 3, + i + null byte, + 10 extra |
| 26 | |
| 27 | static char buffers8cxx . . $ buffers8. [NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.] [MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH. + 1]; |
| 28 | static char32cxx . . $ char32# buffers32cxx . . $ buffers32. [NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.] [MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH. + 1]; |
| 29 | static int ibuffercxx . . $ ibuffer. = 0; |
| 30 | |
| 31 | #define CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! \ |
| 32 | char32 *q = buffers32 [ibuffer]; \ |
| 33 | while (*p != '\0') \ |
| 34 | * q ++ = (char32) (char8) * p ++; /* change signedness before extending (should be unnecessary, because all characters should be below 128) */ \ |
| 35 | *q = U'\0'; \ |
| 36 | return buffers32 [ibuffer]; |
| 37 | |
| 38 | conststring8cxx . . $ conststring8# Melder8_integercxx . . $ Melder8_integer(595caefabb192cea). (int64cxx . . $ int64# value) { |
| 39 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 40 | ibuffercxx . . $ ibuffer. = 0; |
| 41 | if (sizeof (long_not_integercxx . . $ long_not_integer#) == 8) { |
| 42 | const int n = snprintf (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.],MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, "%ld", (long_not_integercxx . . $ long_not_integer#) value); // cast to identical type, to make compiler happy |
| 43 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (n > 0); |
| 44 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (n <= MAXIMUM_NUMERIC_STRING_LENGTH); |
| 45 | } else if (sizeof (long long) == 8) { |
| 46 | /* |
| 47 | There are buggy platforms (namely 32-bit Mingw on Windows XP) that support long long and %lld but that convert |
| 48 | the argument to a 32-bit long. |
| 49 | There are also buggy platforms (namely 32-bit gcc on Linux) that support long long and %I64d but that convert |
| 50 | the argument to a 32-bit long. |
| 51 | */ |
| 52 | static const char *formatString = nullptr; |
| 53 | if (! formatString) { |
| 54 | char tryBuffer [MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH. + 1]; |
| 55 | formatString = "%lld"; |
| 56 | snprintf (tryBuffer,MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, formatString, 1000000000000LL); |
| 57 | if (! strequcxx . . $ `melder/melder_string32.h:69:9`! (tryBuffer, "1000000000000")) { |
| 58 | formatString = "%I64d"; |
| 59 | snprintf (tryBuffer,MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, formatString, 1000000000000LL); |
| 60 | if (! strequcxx . . $ `melder/melder_string32.h:69:9`! (tryBuffer, "1000000000000")) |
| 61 | Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Found no way to print 64-bit integers on this machine."); |
| 62 | } |
| 63 | } |
| 64 | const int n = snprintf (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.],MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, formatString, value); |
| 65 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (n > 0); |
| 66 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (n <= MAXIMUM_NUMERIC_STRING_LENGTH); |
| 67 | } else { |
| 68 | Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Neither long nor long long is 8 bytes on this machine."); |
| 69 | } |
| 70 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 71 | } |
| 72 | conststring32cxx . . $ conststring32# Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (int64cxx . . $ int64# value) { |
| 73 | conststring8cxx . . $ conststring8# p = Melder8_integercxx . . $ Melder8_integer(595caefabb192cea). (value); |
| 74 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 75 | } |
| 76 | |
| 77 | const char * Melder8_bigIntegercxx . . $ Melder8_bigInteger(595caefabb192cea). (int64cxx . . $ int64# value) { |
| 78 | if (value == INT64_MINcxx . . $ `<external>/3415975807581488833/stdint.h:108:10`!) |
| 79 | return "-9,223,372,036,854,775,808"; |
| 80 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 81 | ibuffercxx . . $ ibuffer. = 0; |
| 82 | static_assert (MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH. > 200); // so that we can be sure that even the longest int64 will fit |
| 83 | char *pout = buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 84 | pout [0] = '\0'; |
| 85 | if (value < 0) { |
| 86 | pout += snprintf (pout,100, "-"); // "100" for performance and simplicity; the onus is upon us to have this algorithm right |
| 87 | value = - value; |
| 88 | } |
| 89 | char * const startOfDigits = pout; |
| 90 | const int quintillions = int (value / 1'000'000'000'000'000'000LL); |
| 91 | value -= quintillions * 1'000'000'000'000'000'000LL; |
| 92 | const int quadrillions = int (value / 1'000'000'000'000'000LL); |
| 93 | value -= quadrillions * 1'000'000'000'000'000LL; |
| 94 | const int trillions = int (value / 1'000'000'000'000LL); |
| 95 | value -= trillions * 1'000'000'000'000LL; |
| 96 | const int billions = int (value / 1'000'000'000LL); // cast to silence warning; the onus is upon us to have this algorithm right |
| 97 | value -= billions * 1'000'000'000LL; |
| 98 | const int millions = int (value / 1'000'000LL); |
| 99 | value -= millions * 1'000'000LL; |
| 100 | const int thousands = int (value / 1'000LL); |
| 101 | value -= thousands * 1'000LL; |
| 102 | const int units = int (value); |
| 103 | if (quintillions) |
| 104 | pout += snprintf (pout,100, "%d,", quintillions); // "100" for performance and simplicity; the onus is upon us to have this algorithm right |
| 105 | if (quadrillions || pout > startOfDigits) |
| 106 | pout += snprintf (pout,100, pout > startOfDigits ? "%03d," : "%d,", quadrillions); |
| 107 | if (trillions || pout > startOfDigits) |
| 108 | pout += snprintf (pout,100, pout > startOfDigits ? "%03d," : "%d,", trillions); |
| 109 | if (billions || pout > startOfDigits) |
| 110 | pout += snprintf (pout,100, pout > startOfDigits ? "%03d," : "%d,", billions); |
| 111 | if (millions || pout > startOfDigits) |
| 112 | pout += snprintf (pout,100, pout > startOfDigits ? "%03d," : "%d,", millions); |
| 113 | if (thousands || pout > startOfDigits) |
| 114 | pout += snprintf (pout,100, pout > startOfDigits ? "%03d," : "%d,", thousands); |
| 115 | pout += snprintf (pout,100, pout > startOfDigits ? "%03d" : "%d", units); |
| 116 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (pout - buffers8 [ibuffer] <= 27); // negative quintillions can go up to 27 characters |
| 117 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 118 | } |
| 119 | conststring32cxx . . $ conststring32# Melder_bigIntegercxx . . $ Melder_bigInteger(7b348ebc2004441d). (int64cxx . . $ int64# value) { |
| 120 | conststring8cxx . . $ conststring8# p = Melder8_bigIntegercxx . . $ Melder8_bigInteger(595caefabb192cea). (value); |
| 121 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 122 | } |
| 123 | |
| 124 | const char * Melder8_booleancxx . . $ Melder8_boolean(626eec357d49c77e). (bool value) { |
| 125 | return value ? "yes" : "no"; |
| 126 | } |
| 127 | conststring32cxx . . $ conststring32# Melder_booleancxx . . $ Melder_boolean(dd1c13cd7769a005). (bool value) { |
| 128 | return value ? U"yes" : U"no"; |
| 129 | } |
| 130 | |
| 131 | const char * Melder8_onoffcxx . . $ Melder8_onoff(626eec357d49c77e). (bool value) { |
| 132 | return value ? "on" : "off"; |
| 133 | } |
| 134 | conststring32cxx . . $ conststring32# Melder_onoffcxx . . $ Melder_onoff(dd1c13cd7769a005). (bool value) { |
| 135 | return value ? U"on" : U"off"; |
| 136 | } |
| 137 | |
| 138 | const char * Melder8_kleeneancxx . . $ Melder8_kleenean(f9c10809fd01dd9a). (kleeneancxx . . $ kleenean# valueK) { |
| 139 | return valueK ? "yes" : !cxx . . $ kleenean#`operator!`(3482b152b9333168). valueK ? "no": "unknown"; |
| 140 | } |
| 141 | conststring32cxx . . $ conststring32# Melder_kleeneancxx . . $ Melder_kleenean(d6b360f6e64595dc). (kleeneancxx . . $ kleenean# valueK) { |
| 142 | return valueK ? U"yes" : !cxx . . $ kleenean#`operator!`(3482b152b9333168). valueK ? U"no": U"unknown"; |
| 143 | } |
| 144 | |
| 145 | inline static int common_snprintf_doublecxx . . $ common_snprintf_double(e5954cb01a36d072). (const mutablestring8cxx . . $ mutablestring8# buffer, const int bufferSize, const double value) { |
| 146 | Melder_precxx . . $ `melder/melder_assert.h:40:10`! (bufferSize > 0); // make sure that it can be cast to size_t |
| 147 | /* mutable adjust */ int numberOfPrintedCharacters = snprintf (buffer, size_t (bufferSize), "%.15g", value); // guarded cast |
| 148 | if (strtodcxx . . $ strtod(d6476bb9e2fdf17c). (buffer, nullptr) != value) { |
| 149 | numberOfPrintedCharacters = snprintf (buffer, size_t (bufferSize), "%.16g", value); // guarded cast |
| 150 | if (strtodcxx . . $ strtod(d6476bb9e2fdf17c). (buffer, nullptr) != value) |
| 151 | numberOfPrintedCharacters = snprintf (buffer, size_t (bufferSize), "%.17g", value); // guarded cast |
| 152 | } |
| 153 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters > 0); |
| 154 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters < bufferSize); // truncation is a fatal error |
| 155 | return numberOfPrintedCharacters; |
| 156 | } |
| 157 | inline static int common_snprintf_singlecxx . . $ common_snprintf_single(e5954cb01a36d072). (const mutablestring8cxx . . $ mutablestring8# buffer, const int bufferSize, const double value) { |
| 158 | Melder_precxx . . $ `melder/melder_assert.h:40:10`! (bufferSize > 0); // make sure that it can be cast to size_t |
| 159 | const int numberOfPrintedCharacters = snprintf (buffer, size_t (bufferSize), "%.9g", value); // guarded cast |
| 160 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters > 0); |
| 161 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters < bufferSize); // truncation is a fatal error |
| 162 | return numberOfPrintedCharacters; |
| 163 | } |
| 164 | inline static int common_snprintf_halfcxx . . $ common_snprintf_half(e5954cb01a36d072). (const mutablestring8cxx . . $ mutablestring8# buffer, const int bufferSize, const double value) { |
| 165 | Melder_precxx . . $ `melder/melder_assert.h:40:10`! (bufferSize > 0); // make sure that it can be cast to size_t |
| 166 | const int numberOfPrintedCharacters = snprintf (buffer, size_t (bufferSize), "%.4g", value); // guarded cast |
| 167 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters > 0); |
| 168 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters < bufferSize); // truncation is a fatal error |
| 169 | return numberOfPrintedCharacters; |
| 170 | } |
| 171 | |
| 172 | /*@praat |
| 173 | assert string$ (1000000000000) = "1000000000000" |
| 174 | assert string$ (undefined) = "--undefined--" |
| 175 | @*/ |
| 176 | const char * Melder8_doublecxx . . $ Melder8_double(b2c900d520f7fac6). (double value) { |
| 177 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 178 | ibuffercxx . . $ ibuffer. = 0; |
| 179 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value)) |
| 180 | return "--undefined--"; |
| 181 | common_snprintf_doublecxx . . $ common_snprintf_double(e5954cb01a36d072). (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, value); |
| 182 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 183 | } |
| 184 | conststring32cxx . . $ conststring32# Melder_doublecxx . . $ Melder_double(f05d861d9dbec9b2). (double value) { |
| 185 | conststring8cxx . . $ conststring8# p = Melder8_doublecxx . . $ Melder8_double(b2c900d520f7fac6). (value); |
| 186 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 187 | } |
| 188 | |
| 189 | const char * Melder8_double_overtlyRealcxx . . $ Melder8_double_overtlyReal(b2c900d520f7fac6). (double value) { |
| 190 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 191 | ibuffercxx . . $ ibuffer. = 0; |
| 192 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value)) |
| 193 | return "--undefined--"; |
| 194 | constexpr int roomForDotZero = 2; |
| 195 | common_snprintf_doublecxx . . $ common_snprintf_double(e5954cb01a36d072). (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1 - roomForDotZero, value); |
| 196 | if (! strchr (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], '.') && ! strchr (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], 'e') && ! strchr (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], 'E')) |
| 197 | strcat (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], ".0"); // dot zero |
| 198 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 199 | } |
| 200 | conststring32cxx . . $ conststring32# Melder_double_overtlyRealcxx . . $ Melder_double_overtlyReal(f05d861d9dbec9b2). (double value) { |
| 201 | conststring8cxx . . $ conststring8# p = Melder8_double_overtlyRealcxx . . $ Melder8_double_overtlyReal(b2c900d520f7fac6). (value); |
| 202 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 203 | } |
| 204 | |
| 205 | const char * Melder8_singlecxx . . $ Melder8_single(b2c900d520f7fac6). (double value) { |
| 206 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 207 | ibuffercxx . . $ ibuffer. = 0; |
| 208 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value)) |
| 209 | return "--undefined--"; |
| 210 | common_snprintf_singlecxx . . $ common_snprintf_single(e5954cb01a36d072). (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, value); |
| 211 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 212 | } |
| 213 | conststring32cxx . . $ conststring32# Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (double value) { |
| 214 | conststring8cxx . . $ conststring8# p = Melder8_singlecxx . . $ Melder8_single(b2c900d520f7fac6). (value); |
| 215 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 216 | } |
| 217 | |
| 218 | const char * Melder8_halfcxx . . $ Melder8_half(b2c900d520f7fac6). (double value) { |
| 219 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 220 | ibuffercxx . . $ ibuffer. = 0; |
| 221 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value)) |
| 222 | return "--undefined--"; |
| 223 | common_snprintf_halfcxx . . $ common_snprintf_half(e5954cb01a36d072). (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, value); |
| 224 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 225 | } |
| 226 | conststring32cxx . . $ conststring32# Melder_halfcxx . . $ Melder_half(f05d861d9dbec9b2). (double value) { |
| 227 | conststring8cxx . . $ conststring8# p = Melder8_halfcxx . . $ Melder8_half(b2c900d520f7fac6). (value); |
| 228 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 229 | } |
| 230 | |
| 231 | const char * Melder8_fixedcxx . . $ Melder8_fixed(5a2420b9f3cfe979). (double value, integercxx . . $ integer# precision) { |
| 232 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 233 | ibuffercxx . . $ ibuffer. = 0; |
| 234 | if (value == 0.0) |
| 235 | return "0"; |
| 236 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value)) |
| 237 | return "--undefined--"; |
| 238 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& precision, 60_integercxx . . $ `operator""_integer`(85240eb457c3721a).); |
| 239 | const int minimumPrecision = - (int) floorcxx . . $ floor(fee4f1d22bc8e617). (log10cxx . . $ log10(fee4f1d22bc8e617). (fabscxx . . $ fabs(fee4f1d22bc8e617). (value))); |
| 240 | const int numberOfPrintedCharacters = snprintf ( |
| 241 | buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, |
| 242 | "%.*f", |
| 243 | (int) stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (minimumPrecision, |
| 244 | (int) precision), // guarded cast |
| 245 | value |
| 246 | ); |
| 247 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters > 0); |
| 248 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters < MAXIMUM_NUMERIC_STRING_LENGTH+1); |
| 249 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 250 | } |
| 251 | conststring32cxx . . $ conststring32# Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (double value, integercxx . . $ integer# precision) { |
| 252 | conststring8cxx . . $ conststring8# p = Melder8_fixedcxx . . $ Melder8_fixed(5a2420b9f3cfe979). (value, precision); |
| 253 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 254 | } |
| 255 | |
| 256 | const char * Melder8_fixedExponentcxx . . $ Melder8_fixedExponent(1fee9a7556312644). (double value, integercxx . . $ integer# exponent, integercxx . . $ integer# precision) { |
| 257 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 258 | ibuffercxx . . $ ibuffer. = 0; |
| 259 | if (value == 0.0) |
| 260 | return "0"; |
| 261 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value)) |
| 262 | return "--undefined--"; |
| 263 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& precision, 60_integercxx . . $ `operator""_integer`(85240eb457c3721a).); |
| 264 | const double factor = powcxx . . $ pow(9454dda30a4b8335). (10.0, exponent); |
| 265 | if (factor == 0.0) |
| 266 | return "--undefined--"; |
| 267 | if (isundefcxx . . $ isundef(f8197d536af80c96). (factor)) |
| 268 | return "--undefined--"; |
| 269 | value /= factor; |
| 270 | const int minimumPrecision = - (int) floorcxx . . $ floor(fee4f1d22bc8e617). (log10cxx . . $ log10(fee4f1d22bc8e617). (fabscxx . . $ fabs(fee4f1d22bc8e617). (value))); |
| 271 | const int numberOfPrintedCharacters = snprintf ( |
| 272 | buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, |
| 273 | "%.*fE%d", |
| 274 | (int) stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (minimumPrecision, |
| 275 | (int) precision), // guarded cast |
| 276 | value, |
| 277 | (int) exponent |
| 278 | ); |
| 279 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters > 0); |
| 280 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters < MAXIMUM_NUMERIC_STRING_LENGTH+1); |
| 281 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 282 | } |
| 283 | conststring32cxx . . $ conststring32# Melder_fixedExponentcxx . . $ Melder_fixedExponent(b2de7e334b37c2bb). (double value, integercxx . . $ integer# exponent, integercxx . . $ integer# precision) { |
| 284 | conststring8cxx . . $ conststring8# p = Melder8_fixedExponentcxx . . $ Melder8_fixedExponent(1fee9a7556312644). (value, exponent, precision); |
| 285 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 286 | } |
| 287 | |
| 288 | static const char * common_Melder8_percentcxx . . $ common_Melder8_percent(d38378fc571224eb). (bool graphical, double value, integercxx . . $ integer# precision) { |
| 289 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 290 | ibuffercxx . . $ ibuffer. = 0; |
| 291 | if (value == 0.0) |
| 292 | return "0"; |
| 293 | value *= 100.0; |
| 294 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value)) |
| 295 | return "--undefined--"; |
| 296 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& precision, 60_integercxx . . $ `operator""_integer`(85240eb457c3721a).); |
| 297 | const int minimumPrecision = - (int) floorcxx . . $ floor(fee4f1d22bc8e617). (log10cxx . . $ log10(fee4f1d22bc8e617). (fabscxx . . $ fabs(fee4f1d22bc8e617). (value))); |
| 298 | const int numberOfPrintedCharacters = snprintf ( |
| 299 | buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, |
| 300 | graphical ? "%.*f\\%% " : "%.*f%%", |
| 301 | (int) stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (minimumPrecision, |
| 302 | (int) precision), // guarded cast |
| 303 | value |
| 304 | ); |
| 305 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters > 0); |
| 306 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters < MAXIMUM_NUMERIC_STRING_LENGTH+1); |
| 307 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 308 | } |
| 309 | conststring8cxx . . $ conststring8# Melder8_percentcxx . . $ Melder8_percent(5a2420b9f3cfe979). (double value, integercxx . . $ integer# precision) { |
| 310 | return common_Melder8_percentcxx . . $ common_Melder8_percent(d38378fc571224eb). (false, value, precision); |
| 311 | } |
| 312 | conststring32cxx . . $ conststring32# Melder_percentcxx . . $ Melder_percent(5b9062840a6ade99). (double value, integercxx . . $ integer# precision) { |
| 313 | conststring8cxx . . $ conststring8# p = Melder8_percentcxx . . $ Melder8_percent(5a2420b9f3cfe979). (value, precision); |
| 314 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 315 | } |
| 316 | conststring8cxx . . $ conststring8# Melder8_graphicalPercentcxx . . $ Melder8_graphicalPercent(5a2420b9f3cfe979). (double value, integercxx . . $ integer# precision) { |
| 317 | return common_Melder8_percentcxx . . $ common_Melder8_percent(d38378fc571224eb). (true, value, precision); |
| 318 | } |
| 319 | conststring32cxx . . $ conststring32# Melder_graphicalPercentcxx . . $ Melder_graphicalPercent(5b9062840a6ade99). (double value, integercxx . . $ integer# precision) { |
| 320 | conststring8cxx . . $ conststring8# p = Melder8_graphicalPercentcxx . . $ Melder8_graphicalPercent(5a2420b9f3cfe979). (value, precision); |
| 321 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 322 | } |
| 323 | |
| 324 | conststring8cxx . . $ conststring8# Melder8_hexadecimalcxx . . $ Melder8_hexadecimal(afd701541d7e629d). (integercxx . . $ integer# value, integercxx . . $ integer# precision) { |
| 325 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 326 | ibuffercxx . . $ ibuffer. = 0; |
| 327 | if (value < 0) |
| 328 | return "--undefined--"; |
| 329 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& precision, 60_integercxx . . $ `operator""_integer`(85240eb457c3721a).); |
| 330 | const integercxx . . $ integer# integerValue = Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (value); |
| 331 | const int numberOfPrintedCharacters = snprintf ( |
| 332 | buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, |
| 333 | "%.*llX", |
| 334 | (int) precision, // guarded cast |
| 335 | (unsigned long long) integerValue |
| 336 | ); |
| 337 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters > 0); |
| 338 | Melder_postcxx . . $ `melder/melder_assert.h:41:10`! (numberOfPrintedCharacters < MAXIMUM_NUMERIC_STRING_LENGTH+1); |
| 339 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 340 | } |
| 341 | conststring32cxx . . $ conststring32# Melder_hexadecimalcxx . . $ Melder_hexadecimal(3e477d5ccb44e5a4). (integercxx . . $ integer# value, integercxx . . $ integer# precision) { |
| 342 | conststring8cxx . . $ conststring8# p = Melder8_hexadecimalcxx . . $ Melder8_hexadecimal(afd701541d7e629d). (value, precision); |
| 343 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 344 | } |
| 345 | |
| 346 | conststring8cxx . . $ conststring8# Melder8_dcomplexcxx . . $ Melder8_dcomplex(6c8e008d8b2e1ffc). (dcomplexcxx . . $ dcomplex# value) { |
| 347 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 348 | ibuffercxx . . $ ibuffer. = 0; |
| 349 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value.realcxx . . $ std/complex#real(21b6c25e127938e2).()) || isundefcxx . . $ isundef(f8197d536af80c96). (value.imagcxx . . $ std/complex#imag(21b6c25e127938e2).())) |
| 350 | return "--undefined--"; |
| 351 | constexpr int roomForAdditionOrSubtractionSymbol = 1; |
| 352 | constexpr int roomForISymbol = 1; |
| 353 | constexpr int totalRoom = roomForAdditionOrSubtractionSymbol + roomForISymbol; |
| 354 | static_assert (totalRoom <= extraRoomcxx . . $ extraRoom.); |
| 355 | const int numberOfPrintedCharacters = common_snprintf_doublecxx . . $ common_snprintf_double(e5954cb01a36d072). (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH./2+1 - roomForAdditionOrSubtractionSymbol, value.realcxx . . $ std/complex#real(21b6c25e127938e2).()); |
| 356 | char *p = buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.] + numberOfPrintedCharacters; |
| 357 | * (p ++) = ( value.imagcxx . . $ std/complex#imag(21b6c25e127938e2).() < 0.0 ? '-' : '+' ); |
| 358 | common_snprintf_doublecxx . . $ common_snprintf_double(e5954cb01a36d072). (p, MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH./2+1 - roomForISymbol, fabscxx . . $ fabs(fee4f1d22bc8e617). (value.imagcxx . . $ std/complex#imag(21b6c25e127938e2).())); |
| 359 | strcat (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], "i"); |
| 360 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 361 | } |
| 362 | conststring32cxx . . $ conststring32# Melder_dcomplexcxx . . $ Melder_dcomplex(4cf419d79128e8b4). (dcomplexcxx . . $ dcomplex# value) { |
| 363 | const char *p = Melder8_dcomplexcxx . . $ Melder8_dcomplex(6c8e008d8b2e1ffc). (valuecxx . . $ std/complex#complex(20ef1611af677bca).); |
| 364 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 365 | } |
| 366 | |
| 367 | conststring8cxx . . $ conststring8# Melder8_scomplexcxx . . $ Melder8_scomplex(6c8e008d8b2e1ffc). (dcomplexcxx . . $ dcomplex# value) { |
| 368 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 369 | ibuffercxx . . $ ibuffer. = 0; |
| 370 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value.realcxx . . $ std/complex#real(21b6c25e127938e2).()) || isundefcxx . . $ isundef(f8197d536af80c96). (value.imagcxx . . $ std/complex#imag(21b6c25e127938e2).())) |
| 371 | return "--undefined--"; |
| 372 | constexpr int roomForAdditionOrSubtractionSymbol = 1; |
| 373 | constexpr int roomForISymbol = 1; |
| 374 | constexpr int totalRoom = roomForAdditionOrSubtractionSymbol + roomForISymbol; |
| 375 | static_assert (totalRoom <= extraRoomcxx . . $ extraRoom.); |
| 376 | const int numberOfPrintedCharacters = common_snprintf_singlecxx . . $ common_snprintf_single(e5954cb01a36d072). (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH./2+1 - roomForAdditionOrSubtractionSymbol, value.realcxx . . $ std/complex#real(21b6c25e127938e2).()); |
| 377 | char *p = buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.] + numberOfPrintedCharacters; |
| 378 | * (p ++) = ( value.imagcxx . . $ std/complex#imag(21b6c25e127938e2).() < 0.0 ? '-' : '+' ); |
| 379 | common_snprintf_singlecxx . . $ common_snprintf_single(e5954cb01a36d072). (p, MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH./2+1 - roomForISymbol, fabscxx . . $ fabs(fee4f1d22bc8e617). (value.imagcxx . . $ std/complex#imag(21b6c25e127938e2).())); |
| 380 | strcat (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], "i"); |
| 381 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 382 | } |
| 383 | conststring32cxx . . $ conststring32# Melder_scomplexcxx . . $ Melder_scomplex(4cf419d79128e8b4). (dcomplexcxx . . $ dcomplex# value) { |
| 384 | const char *p = Melder8_scomplexcxx . . $ Melder8_scomplex(6c8e008d8b2e1ffc). (valuecxx . . $ std/complex#complex(20ef1611af677bca).); |
| 385 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 386 | } |
| 387 | |
| 388 | conststring8cxx . . $ conststring8# Melder8_naturalLogarithmcxx . . $ Melder8_naturalLogarithm(b2c900d520f7fac6). (double lnNumber) { |
| 389 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 390 | ibuffercxx . . $ ibuffer. = 0; |
| 391 | //if (lnNumber == -INFINITY) return "0"; // this would have been nice, but cannot be relied upon |
| 392 | if (isundefcxx . . $ isundef(f8197d536af80c96). (lnNumber)) |
| 393 | return "--undefined--"; |
| 394 | const double log10Number = lnNumber * NUMlog10ecxx . . $ NUMlog10e.; |
| 395 | if (log10Number < -1e15) { |
| 396 | return "0"; |
| 397 | } else if (log10Number < -41.0) { |
| 398 | /* mutable adjust */ double ceiling = (integercxx . . $ integer#) ceilcxx . . $ ceil(fee4f1d22bc8e617). (log10Number); |
| 399 | const double remainder = log10Number - ceiling; |
| 400 | double remainder10 = powcxx . . $ pow(b71928d39fde4295). (10.0, remainder); |
| 401 | if (remainder10 == 0.0) |
| 402 | return "0"; |
| 403 | while (remainder10 < 1.0) { |
| 404 | remainder10 *= 10.0; |
| 405 | ceiling --; |
| 406 | } |
| 407 | constexpr int roomForExponent = 20; |
| 408 | const int numberOfPrintedCharacters = common_snprintf_doublecxx . . $ common_snprintf_double(e5954cb01a36d072). (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.], MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1 - roomForExponent, remainder10); |
| 409 | snprintf (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.] + numberOfPrintedCharacters, roomForExponent+1, "e%lld", (long long) ceiling); // BUG: this just doesn't work on Windows |
| 410 | } else { |
| 411 | return Melder8_doublecxx . . $ Melder8_double(b2c900d520f7fac6). (expcxx . . $ exp(fee4f1d22bc8e617). (lnNumber)); |
| 412 | } |
| 413 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 414 | } |
| 415 | conststring32cxx . . $ conststring32# Melder_naturalLogarithmcxx . . $ Melder_naturalLogarithm(f05d861d9dbec9b2). (double lnNumber) { |
| 416 | conststring8cxx . . $ conststring8# p = Melder8_naturalLogarithmcxx . . $ Melder8_naturalLogarithm(b2c900d520f7fac6). (lnNumber); |
| 417 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 418 | } |
| 419 | |
| 420 | static conststring32cxx . . $ conststring32# commmon_Melder_graphicalFloatcxx . . $ commmon_Melder_graphicalFloat(5553299aa8c4fee9). (conststring32cxx . . $ conststring32# number) { |
| 421 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 422 | ibuffercxx . . $ ibuffer. = 0; |
| 423 | if (! str32chrcxx . . $ str32chr(328a9ede0fba853a). (number, 'e')) { |
| 424 | str32cpycxx . . $ str32cpy(6ab934322573b179). (buffers32cxx . . $ buffers32. [ibuffercxx . . $ ibuffer.], number); |
| 425 | } else { |
| 426 | char32cxx . . $ char32# *b = buffers32cxx . . $ buffers32. [ibuffercxx . . $ ibuffer.]; |
| 427 | const char32cxx . . $ char32# *n = & number [0]; |
| 428 | while (*n != U'e') |
| 429 | *(b++) = *(n++); |
| 430 | *b = U'\0'; |
| 431 | if (number [0] == U'1' && number [1] == U'e') { |
| 432 | str32cpycxx . . $ str32cpy(6ab934322573b179). (buffers32cxx . . $ buffers32. [ibuffercxx . . $ ibuffer.], U"10^^"); |
| 433 | b = buffers32cxx . . $ buffers32. [ibuffercxx . . $ ibuffer.] + 4; |
| 434 | } else { |
| 435 | str32catcxx . . $ str32cat(6ab934322573b179). (buffers32cxx . . $ buffers32. [ibuffercxx . . $ ibuffer.], U"·10^^"); |
| 436 | b += 5; |
| 437 | } |
| 438 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (*n == U'e'); |
| 439 | if (*++n == U'+') |
| 440 | n ++; // ignore leading plus sign in exponent |
| 441 | if (*n == U'-') |
| 442 | *(b++) = *(n++); // copy sign of negative exponent |
| 443 | while (*n == U'0') |
| 444 | n ++; // ignore leading zeroes in exponent |
| 445 | while (*n >= U'0' && *n <= U'9') |
| 446 | *(b++) = *(n++); |
| 447 | *(b++) = U'^'; |
| 448 | while (*n != U'\0') |
| 449 | *(b++) = *(n++); |
| 450 | *b = U'\0'; |
| 451 | } |
| 452 | return buffers32cxx . . $ buffers32. [ibuffercxx . . $ ibuffer.]; |
| 453 | } |
| 454 | conststring32cxx . . $ conststring32# Melder_graphicalHalfcxx . . $ Melder_graphicalHalf(f05d861d9dbec9b2). (double number) { |
| 455 | return commmon_Melder_graphicalFloatcxx . . $ commmon_Melder_graphicalFloat(5553299aa8c4fee9). (Melder_halfcxx . . $ Melder_half(f05d861d9dbec9b2). (number)); |
| 456 | } |
| 457 | conststring32cxx . . $ conststring32# Melder_graphicalSinglecxx . . $ Melder_graphicalSingle(f05d861d9dbec9b2). (double number) { |
| 458 | return commmon_Melder_graphicalFloatcxx . . $ commmon_Melder_graphicalFloat(5553299aa8c4fee9). (Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (number)); |
| 459 | } |
| 460 | conststring32cxx . . $ conststring32# Melder_graphicalDoublecxx . . $ Melder_graphicalDouble(f05d861d9dbec9b2). (double number) { |
| 461 | return commmon_Melder_graphicalFloatcxx . . $ commmon_Melder_graphicalFloat(5553299aa8c4fee9). (Melder_doublecxx . . $ Melder_double(f05d861d9dbec9b2). (number)); |
| 462 | } |
| 463 | conststring32cxx . . $ conststring32# Melder_graphicalNaturalLogarithmcxx . . $ Melder_graphicalNaturalLogarithm(f05d861d9dbec9b2). (double number) { |
| 464 | return commmon_Melder_graphicalFloatcxx . . $ commmon_Melder_graphicalFloat(5553299aa8c4fee9). (Melder_naturalLogarithmcxx . . $ Melder_naturalLogarithm(f05d861d9dbec9b2). (number)); |
| 465 | } |
| 466 | |
| 467 | conststring8cxx . . $ conststring8# Melder8_pointercxx . . $ Melder8_pointer(6271d96ae060557f). (const void *pointer) { |
| 468 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 469 | ibuffercxx . . $ ibuffer. = 0; |
| 470 | snprintf (buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.],MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH.+1, "%p", pointer); |
| 471 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 472 | } |
| 473 | conststring32cxx . . $ conststring32# Melder_pointercxx . . $ Melder_pointer(a9959086b14cc90d). (const void *pointer) { |
| 474 | conststring8cxx . . $ conststring8# p = Melder8_pointercxx . . $ Melder8_pointer(6271d96ae060557f). (pointer); |
| 475 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 476 | } |
| 477 | |
| 478 | conststring32cxx . . $ conststring32# Melder_charactercxx . . $ Melder_character(7ee4a1927ac5447f). (char32cxx . . $ char32# kar) { |
| 479 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 480 | ibuffercxx . . $ ibuffer. = 0; |
| 481 | buffers32cxx . . $ buffers32. [ibuffercxx . . $ ibuffer.] [0] = kar; |
| 482 | buffers32cxx . . $ buffers32. [ibuffercxx . . $ ibuffer.] [1] = U'\0'; |
| 483 | return buffers32cxx . . $ buffers32. [ibuffercxx . . $ ibuffer.]; |
| 484 | } |
| 485 | |
| 486 | conststring8cxx . . $ conststring8# Melder8_colourcxx . . $ Melder8_colour(7473bb70226684fb). (MelderColourcxx . . $ MelderColour# colour) { |
| 487 | if (++ ibuffercxx . . $ ibuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) // should come before any return! |
| 488 | ibuffercxx . . $ ibuffer. = 0; |
| 489 | if (isundefcxx . . $ isundef(f8197d536af80c96). (colour.redcxx . . $ MelderColour#red.) || isundefcxx . . $ isundef(f8197d536af80c96). (colour.greencxx . . $ MelderColour#green.) || isundefcxx . . $ isundef(f8197d536af80c96). (colour.bluecxx . . $ MelderColour#blue.)) |
| 490 | return "{--undefined--,--undefined--,--undefined--}"; |
| 491 | char *p = & buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.] [0]; |
| 492 | constexpr int roomForBracesAndCommas = 4; |
| 493 | constexpr int roomPerBraceOrComma = (roomForBracesAndCommas - 1) / 3 + 1; // rounded up; this reserves 6 extra characters (out of a maximum of 10) |
| 494 | strcpy (p ++, "{"); |
| 495 | /* mutable reuse */ int numberOfPrintedCharacters = common_snprintf_doublecxx . . $ common_snprintf_double(e5954cb01a36d072). (p, MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH./3+1 - roomPerBraceOrComma, colour.redcxx . . $ MelderColour#red.); |
| 496 | p += numberOfPrintedCharacters; |
| 497 | strcpy (p ++, ","); |
| 498 | numberOfPrintedCharacters = common_snprintf_doublecxx . . $ common_snprintf_double(e5954cb01a36d072). (p, MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH./3+1 - roomPerBraceOrComma, colour.greencxx . . $ MelderColour#green.); |
| 499 | p += numberOfPrintedCharacters; |
| 500 | strcpy (p ++, ","); |
| 501 | numberOfPrintedCharacters = common_snprintf_doublecxx . . $ common_snprintf_double(e5954cb01a36d072). (p, MAXIMUM_NUMERIC_STRING_LENGTHcxx . . $ MAXIMUM_NUMERIC_STRING_LENGTH./3+1 - roomPerBraceOrComma, colour.bluecxx . . $ MelderColour#blue.); |
| 502 | p += numberOfPrintedCharacters; |
| 503 | strcpy (p, "}"); |
| 504 | return buffers8cxx . . $ buffers8. [ibuffercxx . . $ ibuffer.]; |
| 505 | } |
| 506 | conststring32cxx . . $ conststring32# Melder_colourcxx . . $ Melder_colour(7dfff7c3df3cd0ae). (MelderColourcxx . . $ MelderColour# colour) { |
| 507 | conststring8cxx . . $ conststring8# p = Melder8_colourcxx . . $ Melder8_colour(7473bb70226684fb). (colour); |
| 508 | CONVERT_BUFFER_TO_CHAR32cxx . . $ `melder/melder_ftoa.cpp:31:9`! |
| 509 | } |
| 510 | |
| 511 | /********** TENSOR TO STRING CONVERSION **********/ |
| 512 | |
| 513 | #define NUMBER_OF_TENSOR_BUFFERScxx . . $ `melder/melder_ftoa.cpp:513:9`! 3 |
| 514 | static MelderStringcxx . . $ MelderString# theTensorBufferscxx . . $ theTensorBuffers. [NUMBER_OF_TENSOR_BUFFERScxx . . $ `melder/melder_ftoa.cpp:513:9`!]; |
| 515 | static int iTensorBuffercxx . . $ iTensorBuffer. { 0 }; |
| 516 | |
| 517 | conststring32cxx . . $ conststring32# Melder_VECcxx . . $ Melder_VEC(b17600fbee77d577). (constVECVUcxx . . $ constVECVU# const& value, const bool horizontal) { |
| 518 | if (++ iTensorBuffercxx . . $ iTensorBuffer. == NUMBER_OF_TENSOR_BUFFERScxx . . $ `melder/melder_ftoa.cpp:513:9`!) |
| 519 | iTensorBuffercxx . . $ iTensorBuffer. = 0; |
| 520 | MelderStringcxx . . $ MelderString# *string = & theTensorBufferscxx . . $ theTensorBuffers. [iTensorBuffercxx . . $ iTensorBuffer.]; |
| 521 | MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (string); |
| 522 | if (! NUMisEmptycxx . . $ NUMisEmpty(cc1ac9a2a7378777). (value)) |
| 523 | for (integercxx . . $ integer# i = 1; i <= value.sizecxx . . $ constvectorview#size.; i ++) |
| 524 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (string, value [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i], horizontal ? U' ' : U'\n'); |
| 525 | return string -> stringcxx . . $ MelderString#string.; |
| 526 | } |
| 527 | conststring32cxx . . $ conststring32# Melder_fixedcxx . . $ Melder_fixed(4e9012a2e3a396d0). (constVECVUcxx . . $ constVECVU# const& value, integercxx . . $ integer# precision, const bool horizontal) { |
| 528 | if (++ iTensorBuffercxx . . $ iTensorBuffer. == NUMBER_OF_TENSOR_BUFFERScxx . . $ `melder/melder_ftoa.cpp:513:9`!) |
| 529 | iTensorBuffercxx . . $ iTensorBuffer. = 0; |
| 530 | MelderStringcxx . . $ MelderString# *string = & theTensorBufferscxx . . $ theTensorBuffers. [iTensorBuffercxx . . $ iTensorBuffer.]; |
| 531 | MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (string); |
| 532 | if (! NUMisEmptycxx . . $ NUMisEmpty(cc1ac9a2a7378777). (value)) |
| 533 | for (integercxx . . $ integer# i = 1; i <= value.sizecxx . . $ constvectorview#size.; i ++) |
| 534 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (string, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (value [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i], precision), horizontal ? U' ' : U'\n'); |
| 535 | return string -> stringcxx . . $ MelderString#string.; |
| 536 | } |
| 537 | |
| 538 | conststring32cxx . . $ conststring32# Melder_MATcxx . . $ Melder_MAT(3aa2643813231815). (constMATVUcxx . . $ constMATVU# const& value) { |
| 539 | if (++ iTensorBuffercxx . . $ iTensorBuffer. == NUMBER_OF_TENSOR_BUFFERScxx . . $ `melder/melder_ftoa.cpp:513:9`!) |
| 540 | iTensorBuffercxx . . $ iTensorBuffer. = 0; |
| 541 | MelderStringcxx . . $ MelderString# *string = & theTensorBufferscxx . . $ theTensorBuffers. [iTensorBuffercxx . . $ iTensorBuffer.]; |
| 542 | MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (string); |
| 543 | if (! NUMisEmptycxx . . $ NUMisEmpty(939f42bb6b0c0c9c). (value)) { |
| 544 | for (integercxx . . $ integer# irow = 1; irow <= value.nrowcxx . . $ constmatrixview#nrow.; irow ++) { |
| 545 | for (integercxx . . $ integer# icol = 1; icol <= value.ncolcxx . . $ constmatrixview#ncol.; icol ++) { |
| 546 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (string, value [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).irow] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).icol]); |
| 547 | if (icol < value.ncolcxx . . $ constmatrixview#ncol.) |
| 548 | MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (string, U' '); |
| 549 | } |
| 550 | if (irow < value.nrowcxx . . $ constmatrixview#nrow.) |
| 551 | MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (string, U'\n'); |
| 552 | } |
| 553 | } |
| 554 | return string -> stringcxx . . $ MelderString#string.; |
| 555 | } |
| 556 | conststring32cxx . . $ conststring32# Melder_fixedcxx . . $ Melder_fixed(d058aa82cc22b5d). (constMATVUcxx . . $ constMATVU# const& value, integercxx . . $ integer# precision) { |
| 557 | if (++ iTensorBuffercxx . . $ iTensorBuffer. == NUMBER_OF_TENSOR_BUFFERScxx . . $ `melder/melder_ftoa.cpp:513:9`!) |
| 558 | iTensorBuffercxx . . $ iTensorBuffer. = 0; |
| 559 | MelderStringcxx . . $ MelderString# *string = & theTensorBufferscxx . . $ theTensorBuffers. [iTensorBuffercxx . . $ iTensorBuffer.]; |
| 560 | MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (string); |
| 561 | if (! NUMisEmptycxx . . $ NUMisEmpty(939f42bb6b0c0c9c). (value)) { |
| 562 | for (integercxx . . $ integer# irow = 1; irow <= value.nrowcxx . . $ constmatrixview#nrow.; irow ++) { |
| 563 | for (integercxx . . $ integer# icol = 1; icol <= value.ncolcxx . . $ constmatrixview#ncol.; icol ++) { |
| 564 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (string, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (value [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).irow] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).icol], precision)); |
| 565 | if (icol < value.ncolcxx . . $ constmatrixview#ncol.) |
| 566 | MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (string, U' '); |
| 567 | } |
| 568 | if (irow < value.nrowcxx . . $ constmatrixview#nrow.) |
| 569 | MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (string, U'\n'); |
| 570 | } |
| 571 | } |
| 572 | return string -> stringcxx . . $ MelderString#string.; |
| 573 | } |
| 574 | |
| 575 | conststring32cxx . . $ conststring32# Melder_STRVECcxx . . $ Melder_STRVEC(7e69ba2a7c76306a). (constSTRVECcxx . . $ constSTRVEC# const& value) { |
| 576 | if (++ iTensorBuffercxx . . $ iTensorBuffer. == NUMBER_OF_TENSOR_BUFFERScxx . . $ `melder/melder_ftoa.cpp:513:9`!) |
| 577 | iTensorBuffercxx . . $ iTensorBuffer. = 0; |
| 578 | MelderStringcxx . . $ MelderString# *string = & theTensorBufferscxx . . $ theTensorBuffers. [iTensorBuffercxx . . $ iTensorBuffer.]; |
| 579 | MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (string); |
| 580 | if (! NUMisEmptycxx . . $ NUMisEmpty(72eec41a35d7e37c). (value)) |
| 581 | for (integercxx . . $ integer# i = 1; i <= value.sizecxx . . $ _conststringvector#size.; i ++) |
| 582 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (string, value [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).i], U'\n'); |
| 583 | return string -> stringcxx . . $ MelderString#string.; |
| 584 | } |
| 585 | |
| 586 | /********** STRING TO STRING CONVERSION **********/ |
| 587 | |
| 588 | static MelderStringcxx . . $ MelderString# thePadBufferscxx . . $ thePadBuffers. [NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.]; |
| 589 | static int iPadBuffercxx . . $ iPadBuffer. { 0 }; |
| 590 | |
| 591 | conststring32cxx . . $ conststring32# Melder_padLeftcxx . . $ Melder_padLeft(179e3723cc18632b). (const conststring32cxx . . $ conststring32# string, const integercxx . . $ integer# width, const conststring32cxx . . $ conststring32# pad) { |
| 592 | if (++ iPadBuffercxx . . $ iPadBuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 593 | iPadBuffercxx . . $ iPadBuffer. = 0; |
| 594 | const integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (string); |
| 595 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (length >= 0); |
| 596 | if (width <= length) |
| 597 | return string; |
| 598 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (width > 0); |
| 599 | const integercxx . . $ integer# tooShort = width - length; |
| 600 | // guarded subtraction (length cannot be negative, so no overflow, and width is positive, so no underflow) |
| 601 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooShort > 0); |
| 602 | const integercxx . . $ integer# padLength = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (pad); |
| 603 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (padLength > 0, |
| 604 | U"Empty pad string."); |
| 605 | MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.]); |
| 606 | /* mutable cycle */ integercxx . . $ integer# ipad = 0; |
| 607 | for (integercxx . . $ integer# i = 0; i < tooShort; i ++) { |
| 608 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ipad >= 0); |
| 609 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ipad < padLength); |
| 610 | MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], pad [ipad]); |
| 611 | if (++ ipad >= padLength) |
| 612 | ipad = 0; |
| 613 | } |
| 614 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], string); |
| 615 | return thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.].stringcxx . . $ MelderString#string.; |
| 616 | } |
| 617 | |
| 618 | conststring32cxx . . $ conststring32# Melder_padRightcxx . . $ Melder_padRight(179e3723cc18632b). (const conststring32cxx . . $ conststring32# string, const integercxx . . $ integer# width, const conststring32cxx . . $ conststring32# pad) { |
| 619 | if (++ iPadBuffercxx . . $ iPadBuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 620 | iPadBuffercxx . . $ iPadBuffer. = 0; |
| 621 | const integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (string); |
| 622 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (length >= 0); |
| 623 | if (width <= length) |
| 624 | return string; |
| 625 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (width > 0); |
| 626 | const integercxx . . $ integer# tooShort = width - length; |
| 627 | // guarded subtraction (length cannot be negative, so no overflow, and width is positive, so no underflow) |
| 628 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooShort > 0); |
| 629 | const integercxx . . $ integer# padLength = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (pad); |
| 630 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (padLength > 0, |
| 631 | U"Empty pad string."); |
| 632 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], string); |
| 633 | /* mutable cycle */ integercxx . . $ integer# ipad = padLength - 1 - ((tooShort - 1) % padLength); |
| 634 | for (integercxx . . $ integer# i = 0; i < tooShort; i ++) { |
| 635 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ipad >= 0); |
| 636 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ipad < padLength); |
| 637 | MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], pad [ipad]); |
| 638 | if (++ ipad >= padLength) |
| 639 | ipad = 0; |
| 640 | } |
| 641 | return thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.].stringcxx . . $ MelderString#string.; |
| 642 | } |
| 643 | |
| 644 | conststring32cxx . . $ conststring32# Melder_truncateLeftcxx . . $ Melder_truncateLeft(2444e786ec90af51). (const conststring32cxx . . $ conststring32# string, const integercxx . . $ integer# width) { |
| 645 | if (++ iPadBuffercxx . . $ iPadBuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 646 | iPadBuffercxx . . $ iPadBuffer. = 0; |
| 647 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (width >= 0, |
| 648 | U"Can never truncate a string down to ", width, U" characters."); |
| 649 | const integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (string); // BUG: this can be slow if used in a loop, e.g. if 10'000'000 -> 1000 |
| 650 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (length >= 0); |
| 651 | if (length <= width) |
| 652 | return string; |
| 653 | const integercxx . . $ integer# tooLong = length - width; |
| 654 | // guarded subtraction (length cannot be negative, so no underflow, and width cannot be negative, so no overflow) |
| 655 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooLong > 0); |
| 656 | MelderString_ncopycxx . . $ MelderString_ncopy(b76236fd155635ca). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], string + tooLong, width); |
| 657 | return thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.].stringcxx . . $ MelderString#string.; |
| 658 | } |
| 659 | |
| 660 | conststring32cxx . . $ conststring32# Melder_truncateRightcxx . . $ Melder_truncateRight(2444e786ec90af51). (const conststring32cxx . . $ conststring32# string, const integercxx . . $ integer# width) { |
| 661 | if (++ iPadBuffercxx . . $ iPadBuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 662 | iPadBuffercxx . . $ iPadBuffer. = 0; |
| 663 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (width >= 0, |
| 664 | U"Can never truncate a string down to ", width, U" characters."); |
| 665 | const integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (string); // BUG: this can be slow if used in a loop, e.g. if 10'000'000 -> 1000 |
| 666 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (length >= 0); |
| 667 | if (length <= width) |
| 668 | return string; |
| 669 | const integercxx . . $ integer# tooLong = length - width; |
| 670 | // guarded subtraction (length cannot be negative, so no underflow, and width is nonnegative, so no overflow) |
| 671 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooLong > 0); |
| 672 | MelderString_ncopycxx . . $ MelderString_ncopy(b76236fd155635ca). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], string, width); |
| 673 | return thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.].stringcxx . . $ MelderString#string.; |
| 674 | } |
| 675 | |
| 676 | conststring32cxx . . $ conststring32# Melder_padOrTruncateLeftcxx . . $ Melder_padOrTruncateLeft(179e3723cc18632b). (const conststring32cxx . . $ conststring32# string, const integercxx . . $ integer# width, const conststring32cxx . . $ conststring32# pad) { |
| 677 | if (++ iPadBuffercxx . . $ iPadBuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 678 | iPadBuffercxx . . $ iPadBuffer. = 0; |
| 679 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (width >= 0, |
| 680 | U"Can never truncate a string down to ", width, U" characters."); |
| 681 | const integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (string); |
| 682 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (length >= 0); |
| 683 | const integercxx . . $ integer# tooLong = length - width; |
| 684 | // guarded subtraction (length cannot be negative, so no underflow or INTEGER_MIN, and width cannot be negative, so no overflow) |
| 685 | if (tooLong == 0) |
| 686 | return string; |
| 687 | if (tooLong < 0) { |
| 688 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooLong > INTEGER_MINcxx . . $ `melder/melder_int.h:55:9`!); |
| 689 | const integercxx . . $ integer# tooShort = - tooLong; // guarded integer sign flip |
| 690 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooShort > 0); |
| 691 | const integercxx . . $ integer# padLength = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (pad); |
| 692 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (padLength > 0, |
| 693 | U"Empty pad string."); |
| 694 | MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.]); |
| 695 | /* mutable cycle */ integercxx . . $ integer# ipad = 0; |
| 696 | for (integercxx . . $ integer# i = 0; i < tooShort; i ++) { |
| 697 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ipad >= 0); |
| 698 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ipad < padLength); |
| 699 | MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], pad [ipad]); |
| 700 | if (++ ipad >= padLength) |
| 701 | ipad = 0; |
| 702 | } |
| 703 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], string); |
| 704 | } else { |
| 705 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooLong <= length); |
| 706 | MelderString_ncopycxx . . $ MelderString_ncopy(b76236fd155635ca). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], string + tooLong, width); |
| 707 | } |
| 708 | return thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.].stringcxx . . $ MelderString#string.; |
| 709 | } |
| 710 | |
| 711 | conststring32cxx . . $ conststring32# Melder_padOrTruncateRightcxx . . $ Melder_padOrTruncateRight(179e3723cc18632b). (conststring32cxx . . $ conststring32# string, integercxx . . $ integer# width, const conststring32cxx . . $ conststring32# pad) { |
| 712 | if (++ iPadBuffercxx . . $ iPadBuffer. == NUMBER_OF_BUFFERScxx . . $ NUMBER_OF_BUFFERS.) |
| 713 | iPadBuffercxx . . $ iPadBuffer. = 0; |
| 714 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (width >= 0, |
| 715 | U"Can never truncate a string down to ", width, U" characters."); |
| 716 | const integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (string); |
| 717 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (length >= 0); |
| 718 | const integercxx . . $ integer# tooLong = length - width; |
| 719 | // guarded subtraction (length cannot be negative, so no underflow or INTEGER_MIN, and width cannot be negative, so no overflow) |
| 720 | if (tooLong == 0) |
| 721 | return string; |
| 722 | if (tooLong < 0) { |
| 723 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooLong > INTEGER_MINcxx . . $ `melder/melder_int.h:55:9`!); |
| 724 | const integercxx . . $ integer# tooShort = - tooLong; // guarded integer sign flip |
| 725 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooShort > 0); |
| 726 | const integercxx . . $ integer# padLength = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (pad); |
| 727 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (padLength > 0, |
| 728 | U"Empty pad string."); |
| 729 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], string); |
| 730 | /* mutable cycle */ integercxx . . $ integer# ipad = padLength - 1 - ((tooShort - 1) % padLength); |
| 731 | for (integercxx . . $ integer# i = 0; i < tooShort; i ++) { |
| 732 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ipad >= 0); |
| 733 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ipad < padLength); |
| 734 | MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], pad [ipad]); |
| 735 | if (++ ipad >= padLength) |
| 736 | ipad = 0; |
| 737 | } |
| 738 | } else { |
| 739 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tooLong <= length); |
| 740 | MelderString_ncopycxx . . $ MelderString_ncopy(b76236fd155635ca). (& thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.], string, width); |
| 741 | } |
| 742 | return thePadBufferscxx . . $ thePadBuffers. [iPadBuffercxx . . $ iPadBuffer.].stringcxx . . $ MelderString#string.; |
| 743 | } |
| 744 | |
| 745 | /* End of file melder_ftoa.cpp */ |