X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1431c92bc6260a2869c57bc7126770a05fda3456..4e73c03c087fd07184d9ed45224f7fbad24e686e:/include/xbt/string.hpp diff --git a/include/xbt/string.hpp b/include/xbt/string.hpp index e610b816b8..5b8ab7d46d 100644 --- a/include/xbt/string.hpp +++ b/include/xbt/string.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-2019. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -6,7 +6,7 @@ #ifndef SIMGRID_XBT_STRING_HPP #define SIMGRID_XBT_STRING_HPP -#include +#include #include #include @@ -54,17 +54,14 @@ struct string_data { * * the [C++11-conforming implementation](https://gcc.gnu.org/gcc-5/changes.html) * does not use refcouting/COW but has a small string optimization. */ -XBT_PUBLIC_CLASS string : private string_data { +class XBT_PUBLIC string : private string_data { static char NUL; public: // Types typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; typedef char& reference; typedef const char& const_reference; - typedef char* pointer; - typedef const char* const_pointer; typedef char* iterator; typedef const char* const_iterator; @@ -89,7 +86,7 @@ public: } } string() : string(&NUL, 0) {} - string(const char* s) : string(s, strlen(s)) {} + explicit string(const char* s) : string(s, strlen(s)) {} string(string const& s) : string(s.c_str(), s.size()) {} string(string&& s) { @@ -124,7 +121,8 @@ public: } string& operator=(string const& s) { - assign(s.c_str(), s.size()); + if (this != &s) + assign(s.c_str(), s.size()); return *this; } string& operator=(std::string const& s) @@ -139,7 +137,7 @@ public: bool empty() const { return len != 0; } void shrink_to_fit() { /* Being there, but doing nothing */} - // Alement access + // Element access char* data() { return string_data::data; } const char* data() const { return string_data::data; } char* c_str() { return string_data::data; } @@ -300,14 +298,13 @@ typedef std::string string; * * @ingroup XBT_str */ -std::string string_printf(const char *fmt, ...); +XBT_PUBLIC std::string string_printf(const char* fmt, ...); /** Create a C++ string from a C-style format * * @ingroup XBT_str */ -std::string string_vprintf(const char *fmt, va_list ap); - +XBT_PUBLIC std::string string_vprintf(const char* fmt, va_list ap); } }