From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/pfc/string.h | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 Src/pfc/string.h (limited to 'Src/pfc/string.h') diff --git a/Src/pfc/string.h b/Src/pfc/string.h new file mode 100644 index 00000000..34317e04 --- /dev/null +++ b/Src/pfc/string.h @@ -0,0 +1,205 @@ +#ifndef _PFC_STRING_H_ +#define _PFC_STRING_H_ + +template class string_base +{ +private: + myChar * ptr; + size_t size,used; + void makespace(size_t s) + { + if (sizex) {used=x;ptr[x]=0;}} + + void set_string(const myChar * s) {reset();add_string(s);} + + myChar *buffer_get(size_t n) + { + makespace(n+1); + memset(ptr,0,size); + return ptr; + } + + inline void buffer_done() {used=mylen(ptr);} + + void set_char(int offset,myChar c)//hack for some ghey routines + { + if (!c) truncate(offset); + else if (offset=0;n--) + { + if (ptr[n]==c) return n; + } + return -1; + } + + int replace_char(myChar c1,myChar c2) + { + int rv=0; + int n; + for(n=0;n +class string_buffer +{ +private: + string_base * parent; + myChar * data; +public: + string_buffer(string_base & s,UINT siz) {parent=&s;data=s.buffer_get(siz);} + ~string_buffer() {parent->buffer_done();} + operator myChar* () {return data;} +}; + +#define string_buffer_w string_buffer +#define string_buffer_a string_buffer + +class string_w; +#define string string_a + +class string_a : public string_base +{ +public: + string_a() {} + string_a(HWND w) {s_GetWindowText(w);} + string_a(const char* z) {set_string(z);} + string_a(const WCHAR* z) {set_string_w(z);} + string_a(const string_a& z) {set_string(z);} + string_a(const string_w& z); + void add_string_w(const WCHAR * c); + void set_string_w(const WCHAR * c); + void s_GetWindowText(HWND w); + inline void from_window(HWND w) {s_GetWindowText(w);} + void s_SetWindowText(HWND w); + const char * operator=(const char * s) {set_string(s);return get_ptr();} + const char * operator+=(const char * s) {add_string(s);return get_ptr();} + const char * operator=(const WCHAR * s) {set_string_w(s);return get_ptr();} + const char * operator+=(const WCHAR * s) {add_string_w(s);return get_ptr();} + const char * operator=(string_a & s) {set_string(s);return get_ptr();} + const char * operator+=(string_a & s) {add_string(s);return get_ptr();} + inline void s_GetDlgItemText(HWND w,int id) {s_GetWindowText(GetDlgItem(w,id));} + inline void s_SetDlgItemText(HWND w,int id) {s_SetWindowText(GetDlgItem(w,id));} + bool reg_read(HKEY hk,const char * name); + void reg_write(HKEY hk,const char * name); +}; + +class string_printf_a : public string_a +{ +public: + string_printf_a(const char * fmt,...); +}; + +#define string_printf string_printf_a + +template +class string_file_title : public string_base +{ +public: + string_file_title(const myChar * fn) + { + const myChar * ptr=fn,*dot=0,*src=fn; + while(*ptr) + { + if (*ptr=='\\' || *ptr=='/' || *ptr==':') src=ptr+1; + else if (*ptr=='.') dot=ptr; + ptr++; + } + + while(*src && (!dot || src +#define string_f2t_w string_file_title + +template +class string_extension : public string_base +{ +public: + string_extension(const myChar * foo) + { + const myChar * ptr = 0; + while(*foo) + { + if (*foo == '.') ptr = foo; + foo++; + } + if (ptr) set_string(ptr+1); + } +}; + +#define string_extension_a string_extension +#define string_extension_w string_extension + +#endif //_PFC_STRING_H_ \ No newline at end of file -- cgit