Skip to content

Commit

Permalink
lib/base: Use std::string directly instead of String typedef
Browse files Browse the repository at this point in the history
  • Loading branch information
p12tic committed May 30, 2020
1 parent dbd1082 commit 61771d9
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 176 deletions.
6 changes: 3 additions & 3 deletions src/lib/barrier/ProtocolUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ProtocolUtil {
- \%1I -- converts std::vector<UInt8>* to 1 byte integers
- \%2I -- converts std::vector<UInt16>* to 2 byte integers in NBO
- \%4I -- converts std::vector<UInt32>* to 4 byte integers in NBO
- \%s -- converts String* to stream of bytes
- \%s -- converts std::string* to stream of bytes
- \%S -- converts integer N and const UInt8* to stream of N bytes
*/
static void writef(barrier::IStream*,
Expand All @@ -67,7 +67,7 @@ class ProtocolUtil {
- \%1I -- reads 1 byte integers; arg is std::vector<UInt8>*
- \%2I -- reads NBO 2 byte integers; arg is std::vector<UInt16>*
- \%4I -- reads NBO 4 byte integers; arg is std::vector<UInt32>*
- \%s -- reads bytes; argument must be a String*, \b not a char*
- \%s -- reads bytes; argument must be a std::string*, \b not a char*
*/
static bool readf(barrier::IStream*,
const char* fmt, ...);
Expand All @@ -92,5 +92,5 @@ match the format.
class XIOReadMismatch : public XIO {
public:
// XBase overrides
virtual String getWhat() const throw();
virtual std::string getWhat() const throw();
};
22 changes: 10 additions & 12 deletions src/lib/barrier/XBarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class XIncompatibleClient : public XBarrier {
//@}

protected:
virtual String getWhat() const throw();
virtual std::string getWhat() const throw();

private:
int m_major;
Expand All @@ -68,23 +68,22 @@ a client that is already connected.
*/
class XDuplicateClient : public XBarrier {
public:
XDuplicateClient(const String& name);
XDuplicateClient(const std::string& name);
virtual ~XDuplicateClient() _NOEXCEPT { }

//! @name accessors
//@{

//! Get client's name
virtual const String&
getName() const throw();
virtual const std::string& getName() const throw();

//@}

protected:
virtual String getWhat() const throw();
virtual std::string getWhat() const throw();

private:
String m_name;
std::string m_name;
};

//! Client not in map exception
Expand All @@ -94,23 +93,22 @@ unknown to the server.
*/
class XUnknownClient : public XBarrier {
public:
XUnknownClient(const String& name);
XUnknownClient(const std::string& name);
virtual ~XUnknownClient() _NOEXCEPT { }

//! @name accessors
//@{

//! Get the client's name
virtual const String&
getName() const throw();
virtual const std::string& getName() const throw();

//@}

protected:
virtual String getWhat() const throw();
virtual std::string getWhat() const throw();

private:
String m_name;
std::string m_name;
};

//! Generic exit eception
Expand All @@ -128,7 +126,7 @@ class XExitApp : public XBarrier {
int getCode() const throw();

protected:
virtual String getWhat() const throw();
virtual std::string getWhat() const throw();

private:
int m_code;
Expand Down
9 changes: 3 additions & 6 deletions src/lib/barrier/XScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
// XScreenOpenFailure
//

String
XScreenOpenFailure::getWhat() const throw()
std::string XScreenOpenFailure::getWhat() const throw()
{
return format("XScreenOpenFailure", "unable to open screen");
}
Expand All @@ -33,8 +32,7 @@ XScreenOpenFailure::getWhat() const throw()
// XScreenXInputFailure
//

String
XScreenXInputFailure::getWhat() const throw()
std::string XScreenXInputFailure::getWhat() const throw()
{
return "";
}
Expand All @@ -61,8 +59,7 @@ XScreenUnavailable::getRetryTime() const
return m_timeUntilRetry;
}

String
XScreenUnavailable::getWhat() const throw()
std::string XScreenUnavailable::getWhat() const throw()
{
return format("XScreenUnavailable", "unable to open screen");
}
2 changes: 1 addition & 1 deletion src/lib/barrier/XScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class XScreenUnavailable : public XScreenOpenFailure {
//@}

protected:
virtual String getWhat() const throw();
virtual std::string getWhat() const throw();

private:
double m_timeUntilRetry;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/base/EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ EventQueue::getNextTimerTimeout() const
return m_timerQueue.top();
}

Event::Type
EventQueue::getRegisteredType(const String& name) const
Event::Type EventQueue::getRegisteredType(const std::string& name) const
{
NameMap::const_iterator found = m_nameMap.find(name);
if (found != m_nameMap.end())
Expand Down
5 changes: 2 additions & 3 deletions src/lib/base/EventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class EventQueue : public IEventQueue {
virtual bool isEmpty() const;
virtual IEventJob* getHandler(Event::Type type, void* target) const;
virtual const char* getTypeName(Event::Type type);
virtual Event::Type
getRegisteredType(const String& name) const;
virtual Event::Type getRegisteredType(const std::string& name) const;
void* getSystemTarget();
virtual void waitForReady() const;

Expand Down Expand Up @@ -108,7 +107,7 @@ class EventQueue : public IEventQueue {
typedef std::map<UInt32, Event> EventTable;
typedef std::vector<UInt32> EventIDList;
typedef std::map<Event::Type, const char*> TypeMap;
typedef std::map<String, Event::Type> NameMap;
typedef std::map<std::string, Event::Type> NameMap;
typedef std::map<Event::Type, IEventJob*> TypeHandlerTable;
typedef std::map<void*, TypeHandlerTable> HandlerTable;

Expand Down
3 changes: 1 addition & 2 deletions src/lib/base/IEventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "common/IInterface.h"
#include "base/Event.h"
#include "base/String.h"

class IEventJob;
class IEventQueueBuffer;
Expand Down Expand Up @@ -214,7 +213,7 @@ class IEventQueue : public IInterface {
/*!
Returns the registered type for an event for a given name.
*/
virtual Event::Type getRegisteredType(const String& name) const = 0;
virtual Event::Type getRegisteredType(const std::string& name) const = 0;

//! Get the system event type target
/*!
Expand Down
1 change: 0 additions & 1 deletion src/lib/base/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "base/Log.h"
#include "base/String.h"
#include "base/log_outputters.h"
#include "common/Version.h"

Expand Down
62 changes: 29 additions & 33 deletions src/lib/base/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
namespace barrier {
namespace string {

String
std::string
format(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
String result = vformat(fmt, args);
std::string result = vformat(fmt, args);
va_end(args);
return result;
}

String
std::string
vformat(const char* fmt, va_list args)
{
// find highest indexed substitution and the locations of substitutions
Expand Down Expand Up @@ -111,7 +111,7 @@ vformat(const char* fmt, va_list args)
}

// substitute
String result;
std::string result;
result.reserve(resultLength);
size_t src = 0;
for (int i = 0; i < n; ++i) {
Expand All @@ -124,13 +124,13 @@ vformat(const char* fmt, va_list args)
return result;
}

String
std::string
sprintf(const char* fmt, ...)
{
char tmp[1024];
char* buffer = tmp;
int len = (int)(sizeof(tmp) / sizeof(tmp[0]));
String result;
std::string result;
while (buffer != NULL) {
// try printing into the buffer
va_list args;
Expand Down Expand Up @@ -162,31 +162,31 @@ sprintf(const char* fmt, ...)

void
findReplaceAll(
String& subject,
const String& find,
const String& replace)
std::string& subject,
const std::string& find,
const std::string& replace)
{
size_t pos = 0;
while ((pos = subject.find(find, pos)) != String::npos) {
while ((pos = subject.find(find, pos)) != std::string::npos) {
subject.replace(pos, find.length(), replace);
pos += replace.length();
}
}

String
removeFileExt(String filename)
std::string
removeFileExt(std::string filename)
{
size_t dot = filename.find_last_of('.');

if (dot == String::npos) {
if (dot == std::string::npos) {
return filename;
}

return filename.substr(0, dot);
}

void
toHex(String& subject, int width, const char fill)
toHex(std::string& subject, int width, const char fill)
{
std::stringstream ss;
ss << std::hex;
Expand All @@ -198,18 +198,18 @@ toHex(String& subject, int width, const char fill)
}

void
uppercase(String& subject)
uppercase(std::string& subject)
{
std::transform(subject.begin(), subject.end(), subject.begin(), ::toupper);
}

void
removeChar(String& subject, const char c)
removeChar(std::string& subject, const char c)
{
subject.erase(std::remove(subject.begin(), subject.end(), c), subject.end());
}

String
std::string
sizeTypeToString(size_t n)
{
std::stringstream ss;
Expand All @@ -218,22 +218,22 @@ sizeTypeToString(size_t n)
}

size_t
stringToSizeType(String string)
stringToSizeType(std::string string)
{
std::istringstream iss(string);
size_t value;
iss >> value;
return value;
}

std::vector<String>
splitString(String string, const char c)
std::vector<std::string>
splitString(std::string string, const char c)
{
std::vector<String> results;
std::vector<std::string> results;

size_t head = 0;
size_t separator = string.find(c);
while (separator != String::npos) {
while (separator != std::string::npos) {
if (head!=separator) {
results.push_back(string.substr(head, separator - head));
}
Expand All @@ -252,26 +252,22 @@ splitString(String string, const char c)
// CaselessCmp
//

bool
CaselessCmp::cmpEqual(
const String::value_type& a,
const String::value_type& b)
bool CaselessCmp::cmpEqual(const std::string::value_type& a,
const std::string::value_type& b)
{
// should use std::tolower but not in all versions of libstdc++ have it
return tolower(a) == tolower(b);
}

bool
CaselessCmp::cmpLess(
const String::value_type& a,
const String::value_type& b)
bool CaselessCmp::cmpLess(const std::string::value_type& a,
const std::string::value_type& b)
{
// should use std::tolower but not in all versions of libstdc++ have it
return tolower(a) < tolower(b);
}

bool
CaselessCmp::less(const String& a, const String& b)
CaselessCmp::less(const std::string& a, const std::string& b)
{
return std::lexicographical_compare(
a.begin(), a.end(),
Expand All @@ -280,13 +276,13 @@ CaselessCmp::less(const String& a, const String& b)
}

bool
CaselessCmp::equal(const String& a, const String& b)
CaselessCmp::equal(const std::string& a, const std::string& b)
{
return !(less(a, b) || less(b, a));
}

bool
CaselessCmp::operator()(const String& a, const String& b) const
CaselessCmp::operator()(const std::string& a, const std::string& b) const
{
return less(a, b);
}
Expand Down
Loading

0 comments on commit 61771d9

Please sign in to comment.