14 const char * str = get_ptr();
16 bool need_trunc =
false;
33 if (need_trunc) truncate(trunc);
38 unsigned weeks,days,hours,minutes,seconds;
40 weeks = (unsigned)( ( length / (60*60*24*7) ) );
41 days = (unsigned)( ( length / (60*60*24) ) % 7 );
42 hours = (unsigned) ( ( length / (60 * 60) ) % 24);
43 minutes = (unsigned) ( ( length / (60 ) ) % 60 );
44 seconds = (unsigned) ( ( length ) % 60 );
47 m_buffer << weeks <<
"wk ";
50 m_buffer << days <<
"d ";
52 if (hours || days || weeks) {
55 m_buffer << minutes <<
":" <<
format_uint(seconds,2);
61 return c==
'\\' || c==
'/' || c==
'|' || c==
':';
67 return c==
'\\' || c==
'/' || c==
'|' || c==
':' || c==
'*' || c==
'?' || c==
'\"' || c==
'>' || c==
'<';
69 return c==
'/' || c==
'*' || c==
'?';
78 char * ret = (
char*)malloc(len+1);
90 const char * ptr=fn,*dot=0;
91 while(*ptr && *ptr!=
'?')
93 if (*ptr==
'.') dot=ptr;
97 if (dot && dot>fn) set_string(fn,dot-fn);
104 const char * ptr = fn;
105 while(*ptr && *ptr!=
'?') ptr++;
106 set_string(fn,ptr-fn);
113 const char * end = start + strlen(start);
114 const char * ptr = end-1;
115 while(ptr>start && *ptr!=
'.')
117 if (*ptr==
'?') end=ptr;
121 if (ptr>=start && *ptr==
'.')
125 if (len<PFC_TABSIZE(buffer))
127 memcpy(buffer,ptr,len*
sizeof(
char));
148 if (out_max == 0)
return;
153 if (outptr == out_max) {out[outptr]=0;
return;}
155 if (val<0) {out[outptr++] =
'-'; val = -val;}
156 else if (b_sign) {out[outptr++] =
'+';}
158 if (outptr == out_max) {out[outptr]=0;
return;}
162 double powval = pow((
double)10.0,(
double)precision);
163 temp << (
t_int64)floor(val * powval + 0.5);
168 if (temp_len <= precision)
171 if (outptr == out_max) {out[outptr]=0;
return;}
173 if (outptr == out_max) {out[outptr]=0;
return;}
175 for(d=precision-temp_len;d;d--)
178 if (outptr == out_max) {out[outptr]=0;
return;}
180 for(d=0;d<temp_len;d++)
182 out[outptr++] = temp[d];
183 if (outptr == out_max) {out[outptr]=0;
return;}
189 const char * src = temp;
192 if (d-- == precision)
195 if (outptr == out_max) {out[outptr]=0;
return;}
197 out[outptr++] = *(src++);
198 if (outptr == out_max) {out[outptr]=0;
return;}
211 bool got_dot =
false;
213 while(*src==
' ') src++;
215 if (*src==
'-') {neg =
true;src++;}
216 else if (*src==
'+') src++;
220 if (*src>=
'0' && *src<=
'9')
227 else if (*src==
'.' || *src==
',')
233 else if (*src==
'E' || *src==
'e')
242 return (
double) val *
exp_int(10, div);
248 if (max > 127) max = 127;
250 for(walk = 0; walk < max && src[walk]; walk++) blargh[walk] = src[walk];
260 PFC_ASSERT(replace>0);
265 if (delta==0) {c = replace; delta = 1;}
266 else if (c>=0x80) c = replace;
275 PFC_ASSERT(replace>0);
276 while(ptr<max && src[ptr])
280 if (delta==0) {c = replace; delta = 1;}
281 else if (c>=0x80) c = replace;
290 p_string_len =
strlen_max(p_string,p_string_len);
291 p_substring_len =
strlen_max(p_substring,p_substring_len);
293 while(index + p_substring_len <= p_string_len)
295 if (memcmp(p_string+index,p_substring,p_substring_len) == 0)
return index;
297 if (delta == 0)
break;
305 unsigned ret = 0;
t_size ptr = 0;
306 while(ptr<p_string_len)
308 char c = p_string[ptr];
309 if (! ( c >=
'0' && c <=
'9' ) )
break;
310 ret = ret * 10 + (unsigned)( c -
'0' );
316 int strcmp_nc(
const char* p1,
size_t n1,
const char * p2,
size_t n2)
throw() {
320 if (idx == n1 && idx == n2)
return 0;
321 else if (idx == n1)
return -1;
322 else if (idx == n2)
return 1;
324 char c1 = p1[idx], c2 = p2[idx];
325 if (c1<c2)
return -1;
326 else if (c1>c2)
return 1;
348 if (c>=
'0' && c<=
'9')
350 ret += (c-
'0') * mul;
371 if (start < len && src[start] ==
'-') {neg =
true; start++;}
377 if (c>=
'0' && c<=
'9')
379 ret += (c-
'0') * mul;
388 return neg ? -ret : ret;
395 char c2 = substr[walk];
397 if (c2 == 0)
return 0;
398 if (c1<c2)
return -1;
399 else if (c1>c2)
return 1;
406 t_size walk1 = 0, walk2 = 0;
408 char c1 = (walk1 < len1) ? s1[walk1] : 0;
409 char c2 = (walk2 < len2) ? s2[walk2] : 0;
411 if (c1<c2)
return -1;
412 else if (c1>c2)
return 1;
413 else if (c1 == 0)
return 0;
421 char c1 = *s1, c2 = *s2;
423 if (c1 > 0 && c2 > 0) {
427 if (c1 == 0 && c2 == 0)
return 0;
429 if (c1<c2)
return -1;
430 else if (c1>c2)
return 1;
431 else if (c1 == 0)
return 0;
443 if (d1 == 0 && d2 == 0) {
448 size_t l1 = 1, l2 = 1;
452 size_t l =
max_t(l1, l2);
453 for(
size_t w = 0; w < l; ++w) {
460 digit1 = s1[w - l + l1];
466 digit2 = s2[w - l + l2];
470 if (digit1 < digit2)
return -1;
471 if (digit1 > digit2)
return 1;
483 if (c1 < c2)
return -1;
484 if (c1 > c2)
return 1;
494 return strcmp(s1, s2);
507 t_size len = strlen(temp);
509 m_buffer.add_chars(
' ',p_width-len);
515 PFC_ASSERT(p_val < 16);
516 return (p_val < 10) ? p_val +
'0' : p_val - 10 +
'A';
521 if (p_width > 16) p_width = 16;
522 else if (p_width == 0) p_width = 1;
531 for(n=0;n<16 && temp[n] ==
'0';n++) {}
533 if (n > 16 - p_width) n = 16 - p_width;
535 char * out = m_buffer;
543 PFC_ASSERT(p_val < 16);
544 return (p_val < 10) ? p_val +
'0' : p_val - 10 +
'a';
549 if (p_width > 16) p_width = 16;
550 else if (p_width == 0) p_width = 1;
559 for(n=0;n<16 && temp[n] ==
'0';n++) {}
561 if (n > 16 - p_width) n = 16 - p_width;
563 char * out = m_buffer;
572 enum {max_width = PFC_TABSIZE(m_buffer) - 1};
574 if (p_width > max_width) p_width = max_width;
575 else if (p_width == 0) p_width = 1;
577 char temp[max_width];
580 for(n=0;n<max_width;n++)
586 for(n=0;n<max_width && temp[n] ==
'0';n++) {}
588 if (n > max_width - p_width) n = max_width - p_width;
590 char * out = m_buffer;
592 for(;n<max_width;n++)
600 for(
unsigned n=0;n<p_point;n++) div *= 10;
602 if (p_val < 0) {m_buffer <<
"-";p_val = -p_val;}
612 if (p_val < 0) {neg =
true; val = (
t_uint64)(-p_val);}
615 enum {max_width = PFC_TABSIZE(m_buffer) - 1};
617 if (p_width > max_width) p_width = max_width;
618 else if (p_width == 0) p_width = 1;
620 if (neg && p_width > 1) p_width --;
622 char temp[max_width];
625 for(n=0;n<max_width;n++)
631 for(n=0;n<max_width && temp[n] ==
'0';n++) {}
633 if (n > max_width - p_width) n = max_width - p_width;
635 char * out = m_buffer;
637 if (neg) *(out++) =
'-';
639 for(;n<max_width;n++)
648 for(n=0;n<p_bytes;n++)
650 if (n > 0 && p_spacing != 0) m_formatter << p_spacing;
659 for(n=0;n<p_bytes;n++)
661 if (n > 0 && p_spacing != 0) m_formatter << p_spacing;
671 t_size dot = m_data.find_last(
'.');
672 if (dot < m_data.scan_filename())
679 m_data.truncate(dot+1);
690 m_data.set_string(p_path,ptr);
696 t_size _used = strlen(ptr);
697 for(n=_used-1;n!=~0;n--)
707 for(
t_size walk = p_start; p_string[walk]; ++walk) {
708 if (p_string[walk] == p_tofind)
return walk;
723 for(
t_size walk = p_start; walk < p_string_length && p_string[walk]; ++walk) {
724 if (p_string[walk] == p_tofind)
return walk;
732 p_string_length =
strlen_max(p_string,p_string_length); p_tofind_length =
strlen_max(p_tofind,p_tofind_length);
733 if (p_string_length >= p_tofind_length) {
734 t_size max = p_string_length - p_tofind_length;
735 for(
t_size walk = p_start; walk <= max; walk++) {
736 if (
_strcmp_partial_ex(p_string+walk,p_string_length-walk,p_tofind,p_tofind_length) == 0)
return walk;
742 p_string_length =
strlen_max(p_string,p_string_length); p_tofind_length =
strlen_max(p_tofind,p_tofind_length);
743 if (p_string_length >= p_tofind_length) {
744 t_size max = min_t<t_size>(p_string_length - p_tofind_length,p_start);
746 if (
_strcmp_partial_ex(p_string+walk,p_string_length-walk,p_tofind,p_tofind_length) == 0)
return walk;
753 for(
t_size walk = p_start; walk < p_string_length; walk++) {
754 if (p_string[walk] == c)
return walk;
760 if (p_string_length >= p_tofind_length) {
761 t_size max = p_string_length - p_tofind_length;
762 for(
t_size walk = p_start; walk <= max; walk++) {
763 if (memcmp(p_string+walk, p_tofind, p_tofind_length) == 0)
return walk;
772 for(
t_size walk = 0; walk < p_length && p_string[walk] != 0; walk++) {
781 if (!ends_with(p_char))
add_byte(p_char);
784 t_size length = get_length();
785 return length > 0 && get_ptr()[length-1] == c;
793 size_t l = this->length();
794 if (l == 0)
return 0;
795 return this->get_ptr()[l-1];
798 size_t l = this->length();
799 if (l > 0) this->truncate( l - 1 );
803 size_t l = this->length();
804 const char *
const p = this->get_ptr();
810 for(
t_size n = 0; n < p_len && p_string[n]; n++) {
811 switch(p_string[n]) {
822 for(
unsigned n = 0; n < p_extra; n++ ) ret *= 10;
827 if (add >= scale || scale == 0)
throw pfc::exception_invalid_params();
828 uint64_t v = prev * scale + add;
829 if (v / scale != prev)
throw pfc::exception_invalid_params();
833 static size_t parseNumber(
const char * in, uint64_t & outNumber) {
839 unsigned v = (unsigned)(c -
'0');
840 uint64_t newVal = total * 10 + v;
841 if (newVal / 10 != total)
throw pfc::exception_overflow();
851 uint64_t seconds = 0;
856 if (digits == 0)
throw pfc::exception_invalid_params();
858 char nextSeparator = *in;
861 if (nextSeparator != 0)
throw pfc::exception_bug_check();
862 return (
double)seconds + (double)
pfc::exp_int(10, -(
int)digits) * number;
867 if (colons == 2)
throw pfc::exception_invalid_params();
873 if (nextSeparator == 0) {
875 return (
double)seconds;
879 separator = nextSeparator;
897 if (d==0 || d>len)
break;
907 if (d==0 || d>len)
break;
916 unsigned c1, c2;
t_size d1, d2;
919 if (d1 == 0 && d2 == 0)
return 0;
920 else if (d1 == 0)
return -1;
921 else if (d2 == 0)
return 1;
924 if (c1 < c2)
return -1;
925 else if (c1 > c2)
return 1;
932 unsigned c1, c2;
t_size d1, d2;
935 if (d1 == 0 && d2 == 0)
return 0;
936 else if (d1 == 0)
return -1;
937 else if (d2 == 0)
return 1;
940 if (c1 < c2)
return -1;
941 else if (c1 > c2)
return 1;
949 const char * unit =
"B";
950 const char *
const unitTable[] = {
"B",
"KB",
"MB",
"GB",
"TB"};
951 for(
t_size walk = 1; walk < PFC_TABSIZE(unitTable); ++walk) {
953 if (size < next)
break;
954 scale = next; unit = unitTable[walk];
956 *
this << ( size /
scale );
958 if (scale > 1 && length() < 3) {
959 t_size digits = 3 - length();
962 while(digits > 0 && (remaining % 10) == 0) {
963 remaining /= 10; --digits;
969 *
this <<
" " << unit;
975 const char * ptr = get_ptr() + start;
976 for(
t_size n=start;*ptr;n++)
978 if (*ptr==10 || *ptr==13)
990 const bool rv = truncate_eol(start);
998 const char * base = get_ptr(), * ptr = base;
999 while(length_in_chars &&
utf8_advance(ptr)) length_in_chars--;
1000 if (length_in_chars==0)
1012 while(at > 0 && (*
this)[at-1] ==
'\\') --at;
1013 if (at > 0 && (*
this)[at-1] ==
':' && (*
this)[at] ==
'\\') ++at;
1016 while(at > 0 && (*
this)[at-1] ==
'/') --at;
1019 if (at == 0 && (*
this)[0] ==
'/') ++at;
1022 if (at > 0 && (*
this)[at-1] ==
':') {
1023 while((*
this)[at] ==
'/') ++at;
1026 this->truncate( at );
1031 size_t srcDone = 0, walk = start;
1032 size_t occurances = 0;
1033 const char *
const source = this->get_ptr();
1035 const size_t replaceLen = strlen( replace );
1037 const char * ptr = strstr( source + walk, replace );
1043 temp.add_string( source + srcDone );
1047 walk = ptr - source;
1048 temp.add_string( source + srcDone, walk - srcDone );
1049 temp.add_string( replaceWith );
1053 this->set_string( temp );
1058 for(
t_size walk = 0; walk < inSize; ++walk) {
1059 const char c = in[walk];
1067 const char c = *(in++);
1069 else if (c ==
' ') out.
add_byte(
'+');
1079 if (c >=
'0' && c <=
'9')
return (
unsigned)(c -
'0');
1080 else throw exception_invalid_params();
1084 if (c >=
'0' && c <=
'9')
return (
unsigned)(c -
'0');
1085 else if (c >=
'a' && c <=
'f')
return (
unsigned)(c -
'a' + 10);
1086 else if (c >=
'A' && c <=
'F')
return (
unsigned)(c -
'A' + 10);
1087 else throw exception_invalid_params();
1091 static const t_uint8 ascii_tolower_table[128] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x5B,0x5C,0x5D,0x5E,0x5F,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F};
1096 return ascii_tolower_table[param];
1098 #ifdef PFC_WINDOWS_DESKTOP_APP 1099 else if (param<0x10000) {
1100 return (
unsigned)CharLowerW((WCHAR*)param);
1109 if (param>=
'a' && param<=
'z') param +=
'A' -
'a';
1112 #ifdef PFC_WINDOWS_DESKTOP_APP 1113 else if (param<0x10000) {
1114 return (
unsigned)CharUpperW((WCHAR*)param);
1126 if (c1 > 0 && c2 > 0) {
1127 if (ascii_tolower_table[ (
unsigned) c1 ] != ascii_tolower_table[ (
unsigned) c2 ])
return false;
1129 if (c1 == 0 && c2 == 0)
return true;
1130 if (c1 == 0 || c2 == 0)
return false;
1131 if (c1 != c2)
return false;
1143 if (c1 > 0 && c2 > 0) {
1144 if (ascii_tolower_table[ (
unsigned) c1 ] != ascii_tolower_table[ (
unsigned) c2 ])
return false;
1147 if (c1 == 0 && c2 == 0)
return true;
1148 if (c1 == 0 || c2 == 0)
return false;
1149 unsigned w1,w2;
t_size d1,d2;
1152 if (d1 == 0 || d2 == 0)
return false;
1163 PFC_ASSERT( c >= 0);
1164 return (
char)ascii_tolower_table[ (unsigned) c ];
1177 for(
size_t w = 0; ; ++w ) {
1179 if (c == 0)
return true;
1180 if (
string[w] != c)
return false;
1184 const char * p1 = string;
const char * p2 = prefix;
1186 unsigned w1, w2;
size_t d1, d2;
1189 if (d2 == 0)
return true;
1190 if (d1 == 0)
return false;
1198 size_t len = strlen(
string );
1199 size_t suffixLen = strlen( suffix );
1200 if (suffixLen > len)
return false;
1201 size_t base = len - suffixLen;
1202 return memcmp(
string + base, suffix, suffixLen *
sizeof(
char)) == 0;
1206 if (*
string == 0)
return false;
1214 return _strdup(src);
char ascii_tolower_lookup(char c)
bool stringEqualsI_ascii(const char *p1, const char *p2)
char format_hex_char_lowercase(unsigned p_val)
bool string_has_suffix(const char *string, const char *suffix)
bool fix_eol(const char *append=" (...)", t_size start=0)
char * strDup(const char *src)
double exp_int(double base, int exp)
t_size strstr_ex(const char *p_string, t_size p_string_len, const char *p_substring, t_size p_substring_len)
unsigned char_to_hex(char c)
bool stringEqualsI_utf8(const char *p1, const char *p2)
t_uint64 pow_int(t_uint64 base, t_uint64 exp)
bool is_path_separator(unsigned c)
void SHARED_EXPORT scale(const audio_sample *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
p_source/p_output can point to same buffer
static uint64_t safeMulAdd(uint64_t prev, unsigned scale, uint64_t add)
double string_to_float(const char *src, t_size max)
bool string_is_numeric(const char *p_string, t_size p_length)
void fix_dir_separator(char c= '\\')
void truncate_to_parent_path()
t_size utf8_encode_char(unsigned c, char *out)
string_filename(const char *fn)
int _strcmp_partial_ex(const t_char *p_string, t_size p_string_length, const t_char *p_substring, t_size p_substring_length)
int stricmp_ascii_ex(const char *const s1, t_size const len1, const char *const s2, t_size const len2)
bool is_multiline(const char *p_string, t_size p_len)
bool string_has_suffix_i(const char *string, const char *suffix)
int stringCompareCaseInsensitiveEx(string_part_ref s1, string_part_ref s2)
int naturalSortCompare(const char *s1, const char *s2)
bool ends_with(char c) const
char_t ascii_tolower(char_t c)
static size_t parseNumber(const char *in, uint64_t &outNumber)
void urlEncode(pfc::string_base &out, const char *in)
bool utf8_advance(const char *&var)
int strcmp_ex(const char *p1, t_size n1, const char *p2, t_size n2)
t_size string_find_first_ex(const char *p_string, t_size p_string_length, char p_tofind, t_size p_start)
int stricmp_ascii_partial(const char *str, const char *substr)
bool limit_length(t_size length_in_chars, const char *append=" (...)")
t_size string_find_first_nc(const char *p_string, t_size p_string_length, char c, t_size p_start)
void stringToLowerAppend(string_base &out, const char *src, t_size len)
string_extension(const char *src)
t_size strlen_max(const char *ptr, t_size max)
virtual void add_string(const char *p_string, t_size p_string_size=~0)=0
string8_fastalloc string_formatter
string_replace_extension(const char *p_path, const char *p_ext)
double parse_timecode(const char *in)
int strcmp_nc(const char *p1, size_t n1, const char *p2, size_t n2)
t_uint64 atoui64_ex(const char *src, t_size len)
t_int64 rint64(double p_val)
void urlEncodeAppendRaw(pfc::string_base &out, const char *in, t_size inSize)
t_size scan_filename(const char *ptr)
void skip_trailing_char(unsigned c= ' ')
char * strdup_n(const char *src, t_size len)
void stringToUpperAppend(string_base &out, const char *src, t_size len)
unsigned atoui_ex(const char *p_string, t_size p_string_len)
t_int64 atoi64_ex(const char *src, t_size len)
bool string_has_prefix_i(const char *string, const char *prefix)
t_size string_find_last_ex(const char *p_string, t_size p_string_length, char p_tofind, t_size p_start)
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
bool string_has_prefix(const char *string, const char *prefix)
void add_char(t_uint32 c)
void urlEncodeAppend(pfc::string_base &out, const char *in)
uint32_t charLower(uint32_t param)
int naturalSortCompareI(const char *s1, const char *s2)
void float_to_string(char *out, t_size out_max, double val, unsigned precision, bool b_sign)
pfc::sized_int_t< sizeof(size_t) >::t_signed t_ssize
char getDefaultSeparator()
uint32_t charUpper(uint32_t param)
t_size string_find_last(const char *p_string, char p_tofind, t_size p_start)
int stringCompareCaseInsensitive(const char *s1, const char *s2)
void convert_to_lower_ascii(const char *src, char replace= '?')
unsigned char_to_dec(char c)
int stricmp_ascii(const char *s1, const char *s2)
static const t_uint8 ascii_tolower_table[128]
bool truncate_eol(t_size start=0)
bool char_is_numeric(char_t p_char)
void truncate_last_char()
bool is_path_bad_char(unsigned c)
t_size string_find_first(const char *p_string, char p_tofind, t_size p_start)
char format_hex_char(unsigned p_val)
static int naturalSortCompareInternal(const char *s1, const char *s2, bool insensitive)
void truncate_number_suffix()
static t_uint64 pow10_helper(unsigned p_extra)
bool char_is_ascii_alphanumeric(char p_char)
static double pfc_string_to_float_internal(const char *src)
T max_t(const T &item1, const T &item2)
bool has_path_bad_chars(const char *param)
string_filename_ext(const char *fn)
t_size utf8_char_len(const char *s, t_size max=~0)
void convert_to_lower_ascii(const char *src, t_size max, char *out, char replace)
string_directory(const char *p_path)
t_size replace_string(const char *replace, const char *replaceWith, t_size start=0)
t_size length() const
For compatibility with old conventions.