45 ulonglong =
reinterpret_cast<unsigned long long>(d);
189 bool fmtdata =
false;
190 for(
int i=0; i<(int)fmt.
length(); ++i)
192 int ch = (i<(int)fmt.
length()) ? (
int)fmt[i+0] : -1;
193 int next_ch = (i<(int)fmt.
length()-1) ? (
int)fmt[i+1] : -1;
194 int nnext_ch = (i<(int)fmt.
length()-2) ? (
int)fmt[i+2] : -1;
198 if (ch ==
'%' && next_ch ==
'%')
206 if (param_idx < (
int)pset.size())
213 out +=
" !!!too few parameters: %";
219 out += (
unsigned short)ch;
238 case 'b': base = 2;
break;
239 case 'o': base = 8;
break;
240 case 'd': base = 10;
break;
241 case 'h': base = 16;
break;
255 case '+': plus = 1;
break;
271 case '0': fill =
'0';
break;
272 case ' ': fill =
' ';
break;
288 if (ch >=
'0' && ch <=
'9')
291 if (next_ch >=
'0' && next_ch <=
'9')
293 field = field*10 + next_ch -
'0';
316 if (next_ch >=
'0' && next_ch <=
'9')
318 decimals = next_ch -
'0';
320 if (nnext_ch >=
'0' && nnext_ch <=
'9')
322 decimals = decimals*10 + nnext_ch -
'0';
367 switch(pset[param_idx].
type)
370 default: decimals = 0;
break;
380 const SayArg& p = pset[param_idx];
385 out +=
" !!! '%c' does not need arguments !!! ";
393 out +=
" !!! wrong argument type for '%c' !!! ";
402 out +=
" !!! '%s' does not need arguments !!! ";
408 out +=
" !!! wrong argument type for '%s' !!! ";
414 if (ch ==
'n' || ch ==
'N' || ch ==
'e' || ch ==
'E')
417 if (param_idx<(
int)pset.size())
424 default: decimals = 0;
break;
449 out +=
" !!! wrong argument type for '%n' !!! ";
455 out +=
" !!!missing parameter!!! ";
462 out +=
" !!!format error: unexpected '";
483 out +=
" !!!truncated format!!! ";
487 if (param_idx < (
int)pset.size())
488 out +=
" !!!too many parameters!!! ";
497 int pos = (int)str.
length();
521 if (count && count % wait == 0)
532 String Say::format(
unsigned long long n,
int base,
int field,
int decimals,
int align,
int fill,
int plus,
int finalizer,
int eur)
const 541 decimals = -decimals;
545 if (align != 0 && align != 1 && align != 2)
556 const char* hex =
"0123456789abcdef";
563 int x = (int)(n % base);
578 bool negative =
false;
580 return pipeline(str, base, field, decimals, finalizer, align, eur, fill, negative, plus);
583 String Say::format(
signed long long nn,
int base,
int field,
int decimals,
int align,
int fill,
int plus,
int finalizer,
int eur)
const 592 decimals = -decimals;
596 if (align != 0 && align != 1 && align != 2)
607 const char* hex =
"0123456789abcdef";
611 bool negative = nn < 0;
612 unsigned long long n;
615 n = (
unsigned long long)nn;
628 int x = (int)(n % base);
643 return pipeline(str, base, field, decimals, finalizer, align, eur, fill, negative, plus);
646 String Say::format(
double num,
int base,
int field,
int decimals,
int align,
int fill,
int plus,
int finalizer,
int eur)
const 654 decimals = -decimals;
658 if (align != 0 && align != 1 && align != 2)
669 const char* hex =
"0123456789abcdef";
676 float tmp = (float)f;
677 unsigned char *nan= (
unsigned char*)&tmp;
678 const char*
sign = nan[3] >= 128 ?
"-" :
"+";
679 unsigned char exp = (nan[3] << 1) + (nan[2] >> 7);
681 unsigned int frac = nan[0] + (nan[1] << 8) + (nan[2] << 16);
683 bool negative =
false;
684 if (exp == 255 && frac == 0)
686 return String(sign) +
"#INF";
689 if (exp == 255 && frac != 0)
697 if (finalizer ==
'n' || finalizer ==
'N')
699 double fp = f -
floor(f);
707 int c = (int)(fp * base);
737 unsigned int base2 = base*base;
738 unsigned int base3 = base*base*base;
739 unsigned int base4 = base*base*base*base;
740 unsigned int base5 = base*base*base*base*base;
741 unsigned int base6 = base*base*base*base*base*base;
742 unsigned int base7 = base*base*base*base*base*base*base;
788 double eps = (base / 2.0) / base;
789 for(
int i=0; i<count; ++i)
799 int c = (int)(n * (
double)base);
800 n = n * (double)base -
floor(n * (
double)base);
801 int next = (int)(n * base);
803 if (c<0 || c>15 || next<0 || next>15)
819 double fp = f -
floor(f);
822 int c = (int)(fp * base);
843 return pipeline(str, base, field, decimals, finalizer, align, eur, fill, negative, plus);
847 String Say::pipeline(
const String& in_str,
int base,
int field,
int decimals,
int finalizer,
int align,
int eur,
int fill,
int negative,
int plus)
const 854 if (finalizer ==
'e' || finalizer ==
'E')
856 int ptpos = (int)str.
length();
858 for(
int i=0; i<(int)str.
length(); ++i)
860 if(str[i] !=
'0' && nzpos == -1 && str[i] !=
'.')
870 shift = ptpos - nzpos - ( (ptpos > nzpos) ? 1 : 0 );
876 while( str.
length() && str[0] ==
'0' )
894 int pos = str.
find(
'.');
896 int decs = (int)str.
length() - pos -1;
901 int dot = decimals == 0 ? 1 : 0;
907 int i = decimals - decs;
914 if (finalizer ==
'e' || finalizer ==
'E')
917 str += format((
signed long long)shift, base, 0, 0, 2, 0, 1, 0,0);
923 str = euronotation(str, base);
927 int right = (field - (int)str.
length()) / 2;
928 right = right < 0 ? 0 : right;
930 int left = (field - (int)str.
length()) - right;
931 left = left < 0 ? 0 : left;
946 str.
insert(0, (
wchar_t)fill, left);
949 str.
append((
wchar_t)fill, right);
975 if (finalizer ==
'N' || finalizer ==
'E')
977 for(
int i=0; i<(int)str.
length(); ++i)
978 if (str[i] >=
'a' && str[i] <=
'z')
979 str[i] = str[i] -
'a' +
'A';
signed long long slonglong
String pipeline(const String &str, int base, int field, int decimals, int finalizer, int align, int eur, int fill, int negative, int plus) const
A simple String formatting class.
String & resize(int character_count)
Resizes the string to the specified character count.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Used internally by the Say class.
unsigned long long ulonglong
Visualization Library main namespace.
String euronotation(const String &str, int base) const
String & remove(wchar_t ch, int start=0, int count=-1)
Removes 'count' occurrences of the character 'ch' after position 'start'.
float dot(float a, float b)
int length() const
Returns the length of the string.
String & append(const String &other)
Appends the specified String to another String.
String parse(const Say &pset) const
bool contains(wchar_t ch) const
Returns true if a String contains the specified character.
int find(wchar_t ch, int start=0) const
Searches for the specified character ch starting at position start and returns the index of the first...
String format(unsigned long long n, int base, int field, int decimals, int align, int fill, int plus, int finalizer, int eur) const
String & insert(int pos, const String &str)
Inserts str at position pos.