void f(int i) { … }
void f(double d) { … }
#include <iostream>
#include <string>
void foo(const std::string& s)
{
std::cout << s << std::endl;
}
int main(char ** argv, int argc)
{
foo("c-style string");
foo(std::string("std::string"));
}
$g++ test.cpp
./a.out
c-style string
std::string
http://www.mudbytes.net/index.php?a=file...
This patch adds std::string versions of many utility functions and is a precursor to being able to use OLC on data structures that have std::string members. There are no data structure changes in this patch, except for the addition of a single pointer in descriptor_data (see below).
Realistically this should be peer reviewed by someone else, so I am asking for any and all feedback/review of my patch.
Summary of changes:
merc.h - added pString_std to descriptor_data structure to support editing std::string's via OLC.
olc.h / olc_utils.c -
* Modified functions to all check both the pString and pString_std pointers to decide if the currently edited string is a c-style string or std::string.
* Added utility functions for string_append(), string_linedel(), and string_lineadd() with std::string arguments.
* Broke up format_string() - all the logic is now in format_string_const(), which takes a 'const char *' arg and always allocates a new string for its return value. Changed format_string() to call format_string_const() and perform some manual memory management. Also added a version of format_string() that takes a std::string arg.
* Changed return type and arg types of numelineas() and getline() functions to be 'const char *' from 'char *'. A little safer this way and now these functions can be used with std::string's c_str() pointer.