utils.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. int harry_level(void);
  33. #include <iconv.h>
  34. class IConv {
  35. iconv_t ic;
  36. public:
  37. IConv(const char *to, const char *from);
  38. ~IConv();
  39. int convert(char *input, char *output, size_t outbufsize);
  40. };
  41. // IConv converter("UTF-8", "CP437");
  42. #endif