cp/guest: clean up guest_create's console handling
[hvf.git] / build / re2c / substr.cc
blobe044f59c83527d3d6b3631fa007f2a178a73e1c8
1 /* $Id: substr.cc 860 2008-04-09 22:57:45Z nuno-lopes $ */
2 #include <string.h>
3 #include <stdlib.h>
4 #include "substr.h"
5 #include "globals.h"
7 #ifndef HAVE_STRNDUP
9 char *strndup(const char *str, size_t len)
11 char * ret = (char*)malloc(len + 1);
13 memcpy(ret, str, len);
14 ret[len] = '\0';
15 return ret;
18 #endif
20 namespace re2c
23 void SubStr::out(std::ostream& o) const
25 o.write(str, len);
28 bool operator==(const SubStr &s1, const SubStr &s2)
30 return (bool) (s1.len == s2.len && memcmp(s1.str, s2.str, s1.len) == 0);
33 Str::Str(const SubStr& s)
34 : SubStr(strndup(s.str, s.len), s.len)
39 Str::Str(Str& s)
40 : SubStr(s.str, s.len)
42 s.str = NULL;
43 s.len = 0;
46 Str::Str(const char *s)
47 : SubStr(strdup(s), strlen(s))
52 Str::Str()
53 : SubStr((char*) NULL, 0)
59 Str::~Str()
61 if (str) {
62 free((void*)str);
64 str = NULL;
65 len = 0;
68 } // end namespace re2c