utils.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef UTILS_H
  2. #define UTILS_H
  3. #include <fstream>
  4. #include <map>
  5. #include <string>
  6. // http://c-faq.com/lib/randrange.html
  7. int randint(int N);
  8. // http://c-faq.com/lib/randrange.html
  9. // numbers in the range [M, N] could be generated with something like
  10. int randrange(int M, int N);
  11. int random_activate(int w);
  12. /**
  13. * Display a repr of the given string.
  14. *
  15. * This converts most \n\r\v\f\t codes,
  16. * defaults to \xHH (hex value).
  17. */
  18. char *repr(const char *data);
  19. const char *logrepr(const char *input);
  20. const char *strnstr(const char *source, int len, const char *needle);
  21. int rstrnstr(const char *buffer, int len, const char *find);
  22. int string_insert(char *buffer, size_t max_length, size_t pos,
  23. const char *insert);
  24. void pcopy(char *pstring, char *str);
  25. std::string &find_new_text(std::ifstream &infile,
  26. std::streampos &last_position);
  27. void string_toupper(std::string &str);
  28. void string_trim(std::string &value);
  29. std::map<std::string, std::string> read_configfile(std::string filename);
  30. extern std::map<std::string, std::string> CONFIG;
  31. bool replace(std::string &str, const std::string &from, const std::string &to);
  32. void remove_all(std::string &str, char c);
  33. int unicode_len(char c);
  34. // int find_unicode(std::string &str, int pos);
  35. int harry_level(void);
  36. #include <iconv.h>
  37. class IConv {
  38. iconv_t ic;
  39. public:
  40. IConv(const char *to, const char *from);
  41. ~IConv();
  42. int convert(char *input, char *output, size_t outbufsize);
  43. };
  44. // IConv converter("UTF-8", "CP437");
  45. #endif