Commit Graph

38 Commits

Author SHA1 Message Date
Glauber Costa
62364fcdd7 sstring: add compare method for parts of a sstring
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-07-14 09:26:03 +03:00
Avi Kivity
a28f0efd9a sstring: add iterator range constructor 2015-04-30 15:03:27 +03:00
Calle Wilund
03da7399a0 sstring: add iostream input (>>)
Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
2015-04-29 11:34:47 +03:00
Glauber Costa
2b8035a718 sstring: add a fill constructor
std::string has it, we don't.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-04-25 02:02:04 +03:00
Avi Kivity
0c971d0959 sstring: fix std::string conversion for char_type != char 2015-04-08 08:55:45 +03:00
Amnon Heiman
b90e4ef4d3 sstring: cleanup replace implementation
This do a clean up in the sstring replace method, it also uses a
std::move for optimization.

The missing cbeging and cend method were edded to return a
const_iterator

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-04-06 18:01:20 +03:00
Avi Kivity
3c4edd9eeb sstring: fix string_view interface
string_view is also a template, taking char_type as a parameter.  Need to
use it in order to have a string_view that is compatible with our sstring.
2015-04-05 20:00:10 +03:00
Amnon Heiman
04b5bad2b7 Adding insert replace and erase to sstring
The boost::replace_all uses insert and erase to perform a change, those
method are missing from sstring.

Following the std:string implemntation the implementation of both
functionalities is based on the replace method, either as c string
replace or with templated iterators.

Not all the variation of insert, replace and erase where added, but it
will be possible to add them in the future if needed by calling the
existing functionality.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-04-05 09:51:28 +03:00
Amnon Heiman
0faf9cbb56 Adding back, find_last_of and append to sstring
This adds the back method that return a reference or const reference to
the last char in an sstring.

find_last_of, which return the index of the last occurance of a char in
the string.

And append with append C string to a string.

The logic and definition are similiar to the std::string.

Note that following the std::string definition, calling back on an empty
string is forbiden and the results are undefined.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Tomasz Grabiec
a7d6e22baf sstring: fix bounds checks in find()
'end' iterator was set past the end if pos != 0.
2015-03-17 15:37:54 +02:00
Amnon Heiman
29391d9a9b Extending sstring
This patch adds some of the common functionalities from std:string to
sstring.

It adds length (implement by size() )
It define the constant npos to indicate no possition.
It adds the at (reference and const reference)
It define the find char and find sstring methods
and the substr method

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>

need merge sstring
2015-03-08 21:55:57 +02:00
Avi Kivity
f730ae9814 sstring: add static_assert to prevent use on >1 byte types 2015-02-23 18:23:18 +02:00
Avi Kivity
9519f04b0b sstring: remove unused to_sstring() declaration
The actual overloads are sufficient.
2015-02-23 18:11:39 +02:00
Avi Kivity
51ff807a11 sstring: fix to_sstring() for all sstring types
sstring is a family of types (basic_string<...>), make to_sstring work for
all of them.
2015-02-23 17:26:10 +02:00
Avi Kivity
7f8d88371a Add LICENSE, NOTICE, and copyright headers to all source files.
The two files imported from the OSv project retain their original licenses.
2015-02-19 16:52:34 +02:00
Avi Kivity
7a704f7a40 sstring: fix truncation in compare()
If the difference between the sizes of the two strings is larger than can
be represented by an int, truncation will occur and the sign of the result
is undefined.

Fix by using explicit tests and return values.
2015-02-08 11:41:22 +02:00
Pekka Enberg
9a55e9fd22 sstring: Add 'compare' and 'operator<'
Add string comparison functions to basic_sstring that are required for
C++ containers such as std::map and std::multimap.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-02-08 11:12:31 +02:00
Avi Kivity
16c8414523 sstring: add literal + sstring concatentation overload 2015-01-13 10:12:36 +02:00
Avi Kivity
a52a3dd5ca sstring: add standard member typedefs
Add standard member typedefs, so that standard algorithms looking for
them using their standard names can find them and not spew error messages.
2015-01-12 20:25:21 +02:00
Nadav Har'El
5b071fd224 sstring: support to_sstring() for floating-point
std::to_string() can also convert a floating-point argument to string,
using the "%f" printf format (see
	http://en.cppreference.com/w/cpp/string/basic_string/to_string )
So add this support to our to_sstring() as well.

Note that if you want to use a different format, e.g., "%g", you can,
by using the to_sstring_sprintf function, for example

	to_sstring_sprintf(12345678.9, "%g")

results in "1.23457e+07".

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-30 17:00:46 +02:00
Nadav Har'El
7a84dff0b2 sstring: constructor from C string
The constructor from "const char_type *" wouldn't really work when
char_type != char, because strlen() won't work on such pointers.

It is more convenient to have a constructor from an ordinary const char *
(e.g., a C string literal), and solve the type problem with an ugly cast.

This only makes sense when sizeof(char_type)==1 (i.e., it is char, unsigned
char, or signed char), but I think we make this assumption in other places
as well (e.g., in determining the size we need to allocate).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-29 17:29:32 +02:00
Nadav Har'El
f7fbf8ba02 sstring: add operator[]
std::string has an operator[] to get access (read or modify) to one
character in the string. This patch adds the same operator for our
sstring.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-29 17:29:10 +02:00
Nadav Har'El
9be5590fcd sstring: fix character type
The basic_sstring<> template allows picking char_type - which instead of
being just "char" could be chosen to be something similar, like "unsigned char"
or "signed char".

Unfortunately some hard-coded uses of "char" were left in the code. This
did not cause any problems for existing code because of implicit conversions,
but it does cause problems once I try to implement operator[] when char_type
is not char. This results in an attempt to return a reference to the result
of a conversion, which is not allowed.

So this patch fixes the leftover uses of "char" to "char_type".

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-12-29 17:29:06 +02:00
Avi Kivity
efe6e4f5eb sstring: fix conversion to std::string with NUL bytes
sstring's std::string conversion uses c_str() to construct the value,
but the conversion is broken if the value contains NUL - both sstring and
std::string can contain NULs, but C strings use them as a terminator.

Fix by using the size+length std::string constructor.
2014-12-28 13:30:24 +02:00
Avi Kivity
a0daeae865 sstring: optimize release()
By switching to malloc/free, we can use make_free_deleter(), which
does not require extra memory.
2014-12-16 14:55:02 +02:00
Tomasz Grabiec
a2ca556836 sstring: introduce release()
Releases owenrship of the data and gives it away as
temporary_buffer. This way we can avoid allocation when putting rvalue
sstring if it's already using external storage. Except we need to
allocate a deleter which uses delete[], but this can be fixed later.
2014-12-04 13:37:35 +01:00
Tomasz Grabiec
a88ddcec25 sstring: overload to_sstring() for temporary_buffer<> 2014-12-04 13:35:33 +01:00
Tomasz Grabiec
627e14c2e4 sstring: introduce make_sstring()
It concatenates multiple string-like entities in one go and gives away
an sstring. It does at most one allocation for the final sstring and
one copy per each string. Works with heterogenous arguments, both
sstrings and constant strings are supported, string_views are planned.
2014-11-13 22:22:05 +02:00
Raphael S. Carvalho
d382a314b3 core: sstring: move initialized_later to be a public member
It's required for instantiating a sstring with the constructor
basic_sstring(initialized_later, size_t size).

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-11-01 15:36:28 +02:00
Tomasz Grabiec
a8828fdf8c core: use standard hash for sstring
Turns out that the current hash implementation yields very bad
hashes. This change improves memcache throughput by 70% on
muninn/huginn.
2014-10-22 18:51:55 +03:00
Tomasz Grabiec
4ac3c1d1e1 core: add to_sstring(sstring) overload
So that we don't need to special case templates.
2014-10-21 16:43:09 +02:00
Tomasz Grabiec
4edfc4f0c2 core: implement to_sstring(const char*) 2014-10-18 12:59:59 +02:00
Tomasz Grabiec
97a16c16fd core: add operator<< which can print any vector
Useful in tests.
2014-10-15 15:59:42 +02:00
Tomasz Grabiec
1bdb73e5da core: fix buffer overflow in to_sstring() 2014-10-09 20:04:53 +03:00
Avi Kivity
82cf2eff7c sstring: add conversion from std::string 2014-09-10 13:45:54 +03:00
Avi Kivity
5ad3648c4f sstring: fix assignment operator missing return 2014-09-10 11:36:13 +03:00
Avi Kivity
147046adea Fix copyrights 2014-09-04 18:39:25 +03:00
Avi Kivity
c77f77ee3f build: organize files into a directory structure 2014-08-31 21:29:13 +03:00