#ifndef UTILS_H
#define UTILS_H

#include <fstream>
#include <map>
#include <string>

// http://c-faq.com/lib/randrange.html
int randint(int N);

// http://c-faq.com/lib/randrange.html
// numbers in the range [M, N] could be generated with something like

int randrange(int M, int N);
int random_activate(int w);

/**
 * Display a repr of the given string.
 *
 * This converts most \n\r\v\f\t codes,
 * defaults to \xHH (hex value).
 */

char *repr(const char *data);
const char *logrepr(const char *input);
const char *strnstr(const char *source, int len, const char *needle);
int rstrnstr(const char *buffer, int len, const char *find);
int string_insert(char *buffer, size_t max_length, size_t pos,
                  const char *insert);
void pcopy(char *pstring, char *str);

std::string &find_new_text(std::ifstream &infile,
                           std::streampos &last_position);

void string_toupper(std::string &str);
void string_trim(std::string &value);
std::map<std::string, std::string> read_configfile(std::string filename);
extern std::map<std::string, std::string> CONFIG;
bool replace(std::string &str, const std::string &from, const std::string &to);

int harry_level(void);

#include <iconv.h>

class IConv {
  iconv_t ic;

public:
  IConv(const char *to, const char *from);
  ~IConv();

  int convert(char *input, char *output, size_t outbufsize);
};

// IConv converter("UTF-8", "CP437");

#endif