EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Utils::Strings Class Reference

#include "Util.h"

Static Public Member Functions

static std::string trim (const std::string &str, bool left, bool right)
 
static void trim (std::string &str, bool left, bool right)
 
static std::wstring trim (const std::wstring &str, bool left, bool right)
 
static void trim (std::wstring &str, bool left, bool right)
 
static std::string toUpperCase (const std::string &TString)
 
static void toUpperCase (std::string &TString)
 
static std::wstring toUpperCase (const std::wstring &TString)
 
static void toUpperCase (std::wstring &TString)
 
static std::string toLowerCase (const std::string &TString)
 
static void toLowerCase (std::string &TString)
 
static std::wstring toLowerCase (const std::wstring &TString)
 
static void toLowerCase (std::wstring &TString)
 
static std::string CaseFold (std::string &str)
 
static std::wstring CaseFold (std::wstring &str)
 
static std::wstring StringToWString (std::string &wstr)
 

Detailed Description

Definition at line 97 of file Util.h.

Member Function Documentation

std::string Utils::Strings::CaseFold ( std::string &  str)
static

CaseFold

Folds a a strings case.

Definition at line 757 of file util.cpp.

References toLowerCase(), and toUpperCase().

758 {
759  std::string s2 = str;
762  if (s2 != str)
763  return CaseFold(s2);
764  return s2;
765 }
static std::string toUpperCase(const std::string &TString)
Definition: util.cpp:705
static std::string toLowerCase(const std::string &TString)
Definition: util.cpp:729
static std::string CaseFold(std::string &str)
Definition: util.cpp:757

Here is the call graph for this function:

std::wstring Utils::Strings::CaseFold ( std::wstring &  str)
static

CaseFold

Folds a a strings case.

Definition at line 767 of file util.cpp.

References toLowerCase(), and toUpperCase().

768 {
769  std::wstring s2 = str;
772  if (s2 != str)
773  return CaseFold(s2);
774  return s2;
775 }
static std::string toUpperCase(const std::string &TString)
Definition: util.cpp:705
static std::string toLowerCase(const std::string &TString)
Definition: util.cpp:729
static std::string CaseFold(std::string &str)
Definition: util.cpp:757

Here is the call graph for this function:

std::wstring Utils::Strings::StringToWString ( std::string &  wstr)
static

StringToWString

Converts a std::string to std::wstring

Definition at line 777 of file util.cpp.

References sLog.

778 {
779  /* convert from multi byte strings to wide character strings */
780  std::wstring wstr;
781  wstr.resize( str.size() );
782  size_t ret_len = mbstowcs( &wstr[0], str.c_str(), str.size() );
783 
784  if (ret_len != str.size()) {
785 
786  sLog.Error("Utils::Strings::StringToWString", "unable to convert std::string to std::wstring, wide character string");
787  }
788  return wstr;
789 }
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
std::string Utils::Strings::toLowerCase ( const std::string &  TString)
static

Definition at line 729 of file util.cpp.

Referenced by CaseFold().

730 {
731  std::string retval(TString);
732  std::transform(retval.begin(), retval.end(), retval.begin(), static_cast<int(*)(int)>(::tolower));
733  return retval;
734 }

Here is the caller graph for this function:

void Utils::Strings::toLowerCase ( std::string &  TString)
static

Definition at line 736 of file util.cpp.

737 {
738  std::transform(TString.begin(), TString.end(), TString.begin(), static_cast<int(*)(int)>(::tolower));
739 }
std::wstring Utils::Strings::toLowerCase ( const std::wstring &  TString)
static

Definition at line 741 of file util.cpp.

742 {
743  std::wstring retval(TString);
744  std::transform(retval.begin(), retval.end(), retval.begin(), static_cast<int(*)(int)>(::tolower));
745  return retval;
746 }
void Utils::Strings::toLowerCase ( std::wstring &  TString)
static

Definition at line 748 of file util.cpp.

749 {
750  std::transform(TString.begin(), TString.end(), TString.begin(), static_cast<int(*)(int)>(::tolower));
751 }
std::string Utils::Strings::toUpperCase ( const std::string &  TString)
static

Definition at line 705 of file util.cpp.

Referenced by CaseFold().

706 {
707  std::string retval(TString);
708  std::transform(retval.begin(), retval.end(), retval.begin(), static_cast<int(*)(int)>(::toupper));
709  return retval;
710 }

Here is the caller graph for this function:

void Utils::Strings::toUpperCase ( std::string &  TString)
static

Definition at line 712 of file util.cpp.

713 {
714  std::transform(TString.begin(), TString.end(), TString.begin(), static_cast<int(*)(int)>(::toupper));
715 }
std::wstring Utils::Strings::toUpperCase ( const std::wstring &  TString)
static

Definition at line 717 of file util.cpp.

718 {
719  std::wstring retval(TString);
720  std::transform(retval.begin(), retval.end(), retval.begin(), static_cast<int(*)(int)>(::toupper));
721  return retval;
722 }
void Utils::Strings::toUpperCase ( std::wstring &  TString)
static

Definition at line 724 of file util.cpp.

725 {
726  std::transform(TString.begin(), TString.end(), TString.begin(), static_cast<int(*)(int)>(::toupper));
727 }
std::string Utils::Strings::trim ( const std::string &  str,
bool  left,
bool  right 
)
static

Definition at line 611 of file util.cpp.

612 {
613  size_t lspaces, rspaces, len = str.length(), i;
614 
615  lspaces = rspaces = 0;
616 
617  if(left == true)
618  {
619  for(i = 0;
620  i < len && (str[i] == ' ' || str[i] == '\t' || str[i] == '\r');
621  ++lspaces, ++i);
622  }
623 
624  if(right == true && lspaces < len)
625  {
626  for(i = len - 1;
627  i >= 0 && (str[i] == ' ' || str[i] == '\t' || str[i] == '\r');
628  rspaces++, i--);
629  }
630 
631  return str.substr(lspaces, len-lspaces-rspaces);
632 }
void Utils::Strings::trim ( std::string &  str,
bool  left,
bool  right 
)
static

Definition at line 634 of file util.cpp.

635 {
636  size_t lspaces, rspaces, len = str.length(), i;
637 
638  lspaces = rspaces = 0;
639 
640  if(left == true)
641  {
642  for(i = 0;
643  i < len && (str[i] == ' ' || str[i] == '\t' || str[i] == '\r');
644  ++lspaces, ++i);
645  }
646 
647  if(right == true && lspaces < len)
648  {
649  for(i = len - 1;
650  i >= 0 && (str[i] == ' ' || str[i] == '\t' || str[i] == '\r');
651  rspaces++, i--);
652  }
653 
654  // TODO fit for improvement.
655  str = str.substr(lspaces, len-lspaces-rspaces);
656 }
std::wstring Utils::Strings::trim ( const std::wstring &  str,
bool  left,
bool  right 
)
static

Definition at line 658 of file util.cpp.

659 {
660  size_t lspaces, rspaces, len = str.length(), i;
661 
662  lspaces = rspaces = 0;
663 
664  if(left == true)
665  {
666  for(i = 0;
667  i < len && (str[i] == ' ' || str[i] == '\t' || str[i] == '\r');
668  ++lspaces, ++i);
669  }
670 
671  if(right == true && lspaces < len)
672  {
673  for(i = len - 1;
674  i >= 0 && (str[i] == ' ' || str[i] == '\t' || str[i] == '\r');
675  rspaces++, i--);
676  }
677 
678  return str.substr(lspaces, len-lspaces-rspaces);
679 }
void Utils::Strings::trim ( std::wstring &  str,
bool  left,
bool  right 
)
static

Definition at line 681 of file util.cpp.

682 {
683  size_t lspaces, rspaces, len = str.length(), i;
684 
685  lspaces = rspaces = 0;
686 
687  if(left == true)
688  {
689  for(i = 0;
690  i < len && (str[i] == ' ' || str[i] == '\t' || str[i] == '\r');
691  ++lspaces, ++i);
692  }
693 
694  if(right == true && lspaces < len)
695  {
696  for(i = len - 1;
697  i >= 0 && (str[i] == ' ' || str[i] == '\t' || str[i] == '\r');
698  rspaces++, i--);
699  }
700 
701  // TODO fit for improvement.
702  str = str.substr(lspaces, len-lspaces-rspaces);
703 }

The documentation for this class was generated from the following files: