foobar2000 SDK  2015-08-03
string8_impl.h
Go to the documentation of this file.
1 namespace pfc {
2 
3 template<template<typename> class t_alloc>
4 void string8_t<t_alloc>::add_string(const char * ptr,t_size len)
5 {
6  if (m_data.is_owned(ptr)) {
7  add_string(string8(ptr,len));
8  } else {
9  len = strlen_max(ptr,len);
10  add_string_nc(ptr, len);
11  }
12 }
13 
14 template<template<typename> class t_alloc>
15 void string8_t<t_alloc>::set_string(const char * ptr,t_size len) {
16  if (m_data.is_owned(ptr)) {
17  set_string_(string8(ptr,len));
18  } else {
19  len = strlen_max(ptr,len);
20  set_string_nc(ptr, len);
21  }
22 }
23 
24 template<template<typename> class t_alloc>
25 void string8_t<t_alloc>::set_char(unsigned offset,char c)
26 {
27  if (!c) truncate(offset);
28  else if (offset<used) m_data[offset]=c;
29 }
30 
31 template<template<typename> class t_alloc>
32 void string8_t<t_alloc>::fix_filename_chars(char def,char leave)//replace "bad" characters, leave parameter can be used to keep eg. path separators
33 {
34  t_size n;
35  for(n=0;n<used;n++)
36  if (m_data[n]!=leave && pfc::is_path_bad_char(m_data[n])) m_data[n]=def;
37 }
38 
39 template<template<typename> class t_alloc>
41 {
42  if (first>used) first = used;
43  if (first+count>used) count = used-first;
44  if (count>0)
45  {
46  t_size n;
47  for(n=first+count;n<=used;n++)
48  m_data[n-count]=m_data[n];
49  used -= count;
50  makespace(used+1);
51  }
52 }
53 
54 template<template<typename> class t_alloc>
55 void string8_t<t_alloc>::insert_chars(t_size first,const char * src, t_size count)
56 {
57  if (first > used) first = used;
58 
59  makespace(used+count+1);
60  t_size n;
61  for(n=used;(int)n>=(int)first;n--)
62  m_data[n+count] = m_data[n];
63  for(n=0;n<count;n++)
64  m_data[first+n] = src[n];
65 
66  used+=count;
67 }
68 
69 template<template<typename> class t_alloc>
70 void string8_t<t_alloc>::insert_chars(t_size first,const char * src) {insert_chars(first,src,strlen(src));}
71 
72 
73 template<template<typename> class t_alloc>
75 {
76  t_size ret = 0;
77  for(t_size n=0;n<used;n++)
78  {
79  if ((unsigned char)m_data[n] < 32) {m_data[n] = p_replace; ret++; }
80  }
81  return ret;
82 }
83 
84 template<template<typename> class t_alloc>
86 {
87  PFC_ASSERT(c1 != 0); PFC_ASSERT(c2 != 0);
88  t_size n, ret = 0;
89  for(n=start;n<used;n++)
90  {
91  if (m_data[n] == c1) {m_data[n] = c2; ret++;}
92  }
93  return ret;
94 }
95 
96 template<template<typename> class t_alloc>
97 t_size string8_t<t_alloc>::replace_char(unsigned c1,unsigned c2,t_size start)
98 {
99  if (c1 < 128 && c2 < 128) return replace_byte((char)c1,(char)c2,start);
100 
101  string8 temp(get_ptr()+start);
102  truncate(start);
103  const char * ptr = temp;
104  t_size rv = 0;
105  while(*ptr)
106  {
107  unsigned test;
108  t_size delta = utf8_decode_char(ptr,test);
109  if (delta==0 || test==0) break;
110  if (test == c1) {test = c2;rv++;}
111  add_char(test);
112  ptr += delta;
113  }
114  return rv;
115 }
116 
117 }
void set_string(const char *p_string, t_size p_length=~0)
Definition: string8_impl.h:15
void fix_filename_chars(char def= '_', char leave=0)
Definition: string8_impl.h:32
Decoder Validator v1 readme Usage Select a single file handled by the decoder you want to test
Definition: readme.txt:4
t_size replace_char(unsigned c1, unsigned c2, t_size start=0)
Definition: string8_impl.h:97
void set_char(unsigned offset, char c)
Definition: string8_impl.h:25
void remove_chars(t_size first, t_size count)
Definition: string8_impl.h:40
string8_t< pfc::alloc_standard > string8
Definition: string_base.h:432
void add_string(const char *p_string, t_size p_length=~0)
Definition: string8_impl.h:4
t_size strlen_max(const char *ptr, t_size max)
Definition: string_base.h:91
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
void insert_chars(t_size first, const char *src, t_size count)
Definition: string8_impl.h:55
bool is_path_bad_char(unsigned c)
Definition: string_base.cpp:64
t_size replace_nontext_chars(char p_replace= '_')
Definition: string8_impl.h:74
t_size replace_byte(char c1, char c2, t_size start=0)
Definition: string8_impl.h:85