WAT.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #pragma once
  2. #ifndef _WA_FILE_HEADER
  3. #define _WA_FILE_HEADER
  4. #include <stdio.h>
  5. #include <sys/stat.h>
  6. #include <string>
  7. #include <string.h>
  8. #include <algorithm>
  9. #include <cstring>
  10. #include <cstdarg>
  11. #include <cwchar>
  12. #include <wchar.h>
  13. #include <fstream>
  14. #include <io.h>
  15. #include <iostream>
  16. #include <streambuf>
  17. #include <vector>
  18. #include <map>
  19. #include <cstddef>
  20. #include <sys/stat.h>
  21. #define DEFAULT_STR_BUFFER_SIZE 1024
  22. //namespace fs = std::experimental::filesystem;
  23. namespace wa
  24. {
  25. namespace files
  26. {
  27. bool file_exists( const char *p_filename );
  28. bool file_exists( const std::string &p_filename );
  29. bool file_exists( const wchar_t *p_filename );
  30. int file_size( const char *p_filename );
  31. int file_size( const wchar_t *p_filename );
  32. bool folder_exists( const char* p_folder );
  33. bool getFilenamesFromFolder( std::vector<std::string> &p_result, const std::string &p_folder_path, const std::string &p_reg_ex, const size_t p_limit = 100 );
  34. }
  35. namespace strings
  36. {
  37. namespace convert
  38. {
  39. //
  40. // to const char*
  41. //
  42. const char* to_char( const wchar_t *p_message );
  43. const char* to_char( const std::wstring p_message );
  44. //
  45. // to const wchar_t*
  46. //
  47. const wchar_t *to_wchar( const char *p_message );
  48. //
  49. // to std::string
  50. //
  51. std::string to_string( const char *p_message );
  52. std::string to_string( const wchar_t *p_message );
  53. std::string to_string( const std::wstring p_message );
  54. //
  55. // to std::wstring
  56. //
  57. std::wstring to_wstring( const char *p_message );
  58. std::wstring to_wstring( const wchar_t *p_message );
  59. std::wstring to_wstring( const std::string p_message );
  60. }
  61. void replace( std::string &p_string, const std::string &p_from, const std::string &p_to );
  62. void replace( char *p_string, const char *p_from, const char *p_to );
  63. void replace( wchar_t *p_string, const wchar_t *p_from, const wchar_t *p_to );
  64. void replaceAll( std::string &p_string, const std::string &p_from, const std::string &p_to );
  65. void replaceAll( char *p_string, const char *p_from, const char *p_to );
  66. void replaceAll( wchar_t *p_string, const wchar_t *p_from, const wchar_t *p_to );
  67. std::string create_string( const char *Format, ... );
  68. std::string create_string( const wchar_t *Format, ... );
  69. std::string create_string( const std::string Format, ... );
  70. class wa_string
  71. {
  72. public:
  73. wa_string( const char *p_initial = NULL );
  74. wa_string( const wchar_t *p_initial = NULL );
  75. wa_string( const std::string &p_initial );
  76. wa_string( const std::wstring &p_initial );
  77. void operator = ( const char *p_value );
  78. void operator = ( const wchar_t *p_value );
  79. void operator = ( const std::string &p_value );
  80. void operator = ( const std::wstring &p_value );
  81. bool operator == ( const char *p_value ) const;
  82. bool operator == ( const wchar_t *p_value ) const;
  83. bool operator == ( const std::string &p_value ) const;
  84. bool operator == ( const std::wstring &p_value ) const;
  85. bool operator != ( const char *p_value ) const;
  86. bool operator != ( const wchar_t *p_value ) const;
  87. bool operator != ( const std::string &p_value ) const;
  88. bool operator != ( const int p_value ) const;
  89. wa_string operator + ( const char *p_value );
  90. wa_string operator + ( const wchar_t *p_value );
  91. wa_string operator + ( const std::string &p_value );
  92. wa_string operator + ( const std::wstring &p_value);
  93. wa_string operator + ( const int p_value );
  94. wa_string append( const char *p_value );
  95. wa_string append( const wchar_t *p_value );
  96. wa_string append( const std::string &p_value );
  97. wa_string append( const std::wstring &p_value );
  98. wa_string append( const wa_string p_value);
  99. wa_string append( const int p_value );
  100. const std::string GetA() const;
  101. const std::wstring GetW() const;
  102. void clear() { _wa_string.clear(); }
  103. unsigned int lengthA() const;
  104. unsigned int lengthW() const;
  105. unsigned int lengthS() const;
  106. unsigned int lengthWS() const;
  107. bool contains( const char *p_value );
  108. bool contains( const wchar_t *p_value );
  109. bool contains( const std::string &p_value );
  110. bool contains( const std::wstring &p_value );
  111. wa_string replace( const char *p_from, const char *p_to );
  112. wa_string replace( const wchar_t *p_from, const wchar_t *p_to );
  113. wa_string replace( const std::string &p_from, const std::string &p_to );
  114. wa_string replace( const std::wstring &p_from, const std::wstring &p_to );
  115. wa_string replaceAll( const char *p_from, const char *p_to );
  116. wa_string replaceAll( const wchar_t *p_from, const wchar_t *p_to );
  117. wa_string replaceAll( const std::string &p_from, const std::string &p_to );
  118. wa_string replaceAll( const std::wstring &p_from, const std::wstring &p_to );
  119. bool startsWith( const char *l_head ) const;
  120. bool startsWith( const wchar_t *l_head ) const;
  121. bool startsWith( const std::string &l_head ) const;
  122. bool startsWith( const std::wstring &l_head ) const;
  123. bool endsWith( const char *l_tail ) const;
  124. bool endsWith( const wchar_t *l_tail ) const;
  125. bool endsWith( const std::string &l_tail ) const;
  126. bool endsWith( const std::wstring &l_tail ) const;
  127. int findFirst( const char *l_text ) const;
  128. int findFirst( const wchar_t *l_text ) const;
  129. int findFirst( const std::string &l_text ) const;
  130. int findFirst( const std::wstring &l_text ) const;
  131. int findLast( const char *l_text ) const;
  132. int findLast( const wchar_t *l_text ) const;
  133. int findLast( const std::string &l_text ) const;
  134. int findLast( const std::wstring &l_text ) const;
  135. int find( const std::wstring &l_text ) const;
  136. std::wstring mid( const int p_start, const int p_length ) const;
  137. bool empty() const { return _wa_string.empty(); }
  138. wa_string toUpper();
  139. private:
  140. std::wstring _wa_string;
  141. };
  142. }
  143. namespace bits_operation
  144. {
  145. unsigned char* GetBits(unsigned char* Source, unsigned int NbrOfBits, unsigned int* BufferSize);
  146. wa::strings::wa_string PrintInBinary(unsigned char* buffer, unsigned int size);
  147. }
  148. }
  149. #endif // !_WA_FILE_HEADER