summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util')
-rw-r--r--src/lib/util/corefile.cpp4
-rw-r--r--src/lib/util/corefile.h2
-rw-r--r--src/lib/util/corestr.cpp5
-rw-r--r--src/lib/util/corestr.h2
-rw-r--r--src/lib/util/hashing.cpp28
-rw-r--r--src/lib/util/hashing.h8
-rw-r--r--src/lib/util/options.cpp18
-rw-r--r--src/lib/util/options.h4
8 files changed, 32 insertions, 39 deletions
diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp
index a2242c133c6..344a2922bfe 100644
--- a/src/lib/util/corefile.cpp
+++ b/src/lib/util/corefile.cpp
@@ -909,7 +909,7 @@ file_error core_truncate(core_file *f, UINT64 offset)
assumptions about path separators
-------------------------------------------------*/
-std::string &core_filename_extract_base(std::string &result, const char *name, bool strip_extension)
+std::string core_filename_extract_base(const char *name, bool strip_extension)
{
/* find the start of the name */
const char *start = name + strlen(name);
@@ -917,7 +917,7 @@ std::string &core_filename_extract_base(std::string &result, const char *name, b
start--;
/* copy the rest into an astring */
- result.assign(start);
+ std::string result(start);
/* chop the extension if present */
if (strip_extension)
diff --git a/src/lib/util/corefile.h b/src/lib/util/corefile.h
index eeb5a8efa22..5266832c374 100644
--- a/src/lib/util/corefile.h
+++ b/src/lib/util/corefile.h
@@ -125,7 +125,7 @@ file_error core_truncate(core_file *f, UINT64 offset);
/* ----- filename utilities ----- */
/* extract the base part of a filename (remove extensions and paths) */
-std::string &core_filename_extract_base(std::string &result, const char *name, bool strip_extension = false);
+std::string core_filename_extract_base(const char *name, bool strip_extension = false);
/* true if the given filename ends with a particular extension */
int core_filename_ends_with(const char *filename, const char *extension);
diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp
index 336d788cabb..ce5976869d4 100644
--- a/src/lib/util/corestr.cpp
+++ b/src/lib/util/corestr.cpp
@@ -217,14 +217,13 @@ int strprintf(std::string &str, const char *format, ...)
return retVal;
}
-std::string strformat(std::string &str, const char *format, ...)
+std::string strformat(const char *format, ...)
{
std::string retVal;
va_list ap;
va_start(ap, format);
- strvprintf(str, format, ap);
+ strvprintf(retVal, format, ap);
va_end(ap);
- retVal.assign(str);
return retVal;
}
diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h
index 519e1edc849..94f13c4061b 100644
--- a/src/lib/util/corestr.h
+++ b/src/lib/util/corestr.h
@@ -68,7 +68,7 @@ int strvprintf(std::string &str, const char *format, va_list args);
int strcatvprintf(std::string &str, const char *format, va_list args);
int strprintf(std::string &str, const char *format, ...) ATTR_PRINTF(2, 3);
int strcatprintf(std::string &str, const char *format, ...) ATTR_PRINTF(2, 3);
-std::string strformat(std::string &str, const char *format, ...) ATTR_PRINTF(2, 3);
+std::string strformat(const char *format, ...) ATTR_PRINTF(1, 2);
void strdelchr(std::string& str, char chr);
void strreplacechr(std::string& str, char ch, char newch);
diff --git a/src/lib/util/hashing.cpp b/src/lib/util/hashing.cpp
index 785127e01e8..8e85e4a42d2 100644
--- a/src/lib/util/hashing.cpp
+++ b/src/lib/util/hashing.cpp
@@ -79,12 +79,12 @@ bool sha1_t::from_string(const char *string, int length)
// as_string - convert to a string
//-------------------------------------------------
-const char *sha1_t::as_string(std::string &buffer) const
+std::string sha1_t::as_string() const
{
- buffer.clear();
+ std::string buffer;
for (auto & elem : m_raw)
strcatprintf(buffer, "%02x", elem);
- return buffer.c_str();
+ return buffer;
}
@@ -122,12 +122,12 @@ bool md5_t::from_string(const char *string, int length)
// as_string - convert to a string
//-------------------------------------------------
-const char *md5_t::as_string(std::string &buffer) const
+std::string md5_t::as_string() const
{
- buffer.clear();
+ std::string buffer;
for (auto & elem : m_raw)
strcatprintf(buffer, "%02x", elem);
- return buffer.c_str();
+ return buffer;
}
@@ -166,10 +166,9 @@ bool crc32_t::from_string(const char *string, int length)
// as_string - convert to a string
//-------------------------------------------------
-const char *crc32_t::as_string(std::string &buffer) const
+std::string crc32_t::as_string() const
{
- strprintf(buffer, "%08x", m_raw);
- return buffer.c_str();
+ return strformat("%08x", m_raw);
}
@@ -215,21 +214,18 @@ bool crc16_t::from_string(const char *string, int length)
}
/**
- * @fn const char *crc16_t::as_string(std::string &buffer) const
+ * @fn std::string crc16_t::as_string() const
*
* @brief -------------------------------------------------
* as_string - convert to a string
* -------------------------------------------------.
*
- * @param [in,out] buffer The buffer.
- *
- * @return null if it fails, else a char*.
+ * @return a std::string.
*/
-const char *crc16_t::as_string(std::string &buffer) const
+std::string crc16_t::as_string() const
{
- strprintf(buffer, "%04x", m_raw);
- return buffer.c_str();
+ return strformat("%04x", m_raw);
}
/**
diff --git a/src/lib/util/hashing.h b/src/lib/util/hashing.h
index b0de6a5c3c8..51a7da7c694 100644
--- a/src/lib/util/hashing.h
+++ b/src/lib/util/hashing.h
@@ -34,7 +34,7 @@ struct sha1_t
bool operator!=(const sha1_t &rhs) const { return memcmp(m_raw, rhs.m_raw, sizeof(m_raw)) != 0; }
operator UINT8 *() { return m_raw; }
bool from_string(const char *string, int length = -1);
- const char *as_string(std::string &buffer) const;
+ std::string as_string() const;
UINT8 m_raw[20];
static const sha1_t null;
};
@@ -85,7 +85,7 @@ struct md5_t
bool operator!=(const md5_t &rhs) const { return memcmp(m_raw, rhs.m_raw, sizeof(m_raw)) != 0; }
operator UINT8 *() { return m_raw; }
bool from_string(const char *string, int length = -1);
- const char *as_string(std::string &buffer) const;
+ std::string as_string() const;
UINT8 m_raw[16];
static const md5_t null;
};
@@ -136,7 +136,7 @@ struct crc32_t
crc32_t &operator=(const UINT32 crc) { m_raw = crc; return *this; }
operator UINT32() const { return m_raw; }
bool from_string(const char *string, int length = -1);
- const char *as_string(std::string &buffer) const;
+ std::string as_string() const;
UINT32 m_raw;
static const crc32_t null;
};
@@ -182,7 +182,7 @@ struct crc16_t
crc16_t &operator=(const UINT16 crc) { m_raw = crc; return *this; }
operator UINT16() const { return m_raw; }
bool from_string(const char *string, int length = -1);
- const char *as_string(std::string &buffer) const;
+ std::string as_string() const;
UINT16 m_raw;
static const crc16_t null;
};
diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp
index 0e02b7dc735..d7ab454d063 100644
--- a/src/lib/util/options.cpp
+++ b/src/lib/util/options.cpp
@@ -478,10 +478,10 @@ void core_options::revert(int priority)
// the optional diff
//-------------------------------------------------
-const char *core_options::output_ini(std::string &buffer, const core_options *diff)
+std::string core_options::output_ini(const core_options *diff) const
{
// INI files are complete, so always start with a blank buffer
- buffer.clear();
+ std::string buffer;
int num_valid_headers = 0;
int unadorned_index = 0;
@@ -534,7 +534,7 @@ const char *core_options::output_ini(std::string &buffer, const core_options *di
}
}
}
- return buffer.c_str();
+ return buffer;
}
@@ -542,10 +542,10 @@ const char *core_options::output_ini(std::string &buffer, const core_options *di
// output_help - output option help to a string
//-------------------------------------------------
-const char *core_options::output_help(std::string &buffer)
+std::string core_options::output_help() const
{
// start empty
- buffer.clear();
+ std::string buffer;
// loop over all items
for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next())
@@ -558,7 +558,7 @@ const char *core_options::output_help(std::string &buffer)
else if (curentry->description() != nullptr)
strcatprintf(buffer,"-%-20s%s\n", curentry->name(), curentry->description());
}
- return buffer.c_str();
+ return buffer;
}
@@ -634,15 +634,13 @@ bool core_options::set_value(const char *name, const char *value, int priority,
bool core_options::set_value(const char *name, int value, int priority, std::string &error_string)
{
- std::string tempstr;
- strprintf(tempstr,"%d", value);
+ std::string tempstr = strformat("%d", value);
return set_value(name, tempstr.c_str(), priority, error_string);
}
bool core_options::set_value(const char *name, float value, int priority, std::string &error_string)
{
- std::string tempstr;
- strprintf(tempstr, "%f", (double) value);
+ std::string tempstr = strformat("%f", (double)value);
return set_value(name, tempstr.c_str(), priority, error_string);
}
diff --git a/src/lib/util/options.h b/src/lib/util/options.h
index f193d4a4976..1df89bed6c7 100644
--- a/src/lib/util/options.h
+++ b/src/lib/util/options.h
@@ -145,8 +145,8 @@ public:
void revert(int priority = OPTION_PRIORITY_MAXIMUM);
// output
- const char *output_ini(std::string &buffer, const core_options *diff = nullptr);
- const char *output_help(std::string &buffer);
+ std::string output_ini(const core_options *diff = nullptr) const;
+ std::string output_help() const;
// reading
const char *value(const char *option) const;