gccDppConsole Test C++ SDK  20170920
DPP C++ Console Demonstration
stringex.cpp
Go to the documentation of this file.
00001 #include "stringex.h"
00002 
00003 #ifdef _MSC_VER
00004         #pragma warning(disable:4996)
00005         #define vsnprintf _vsnprintf
00006 #endif
00007 
00008 stringex::stringex(void)
00009 {
00010 }
00011 
00012 stringex::~stringex(void)
00013 {
00014 }
00015 
00016 std::string stringex::vformat (const char *fmt, va_list ap)
00017 {
00018     size_t size = 1024;
00019     char stackbuf[1024];
00020     std::vector<char> dynamicbuf;
00021     char *buf = &stackbuf[0];
00022     while (1) {
00023         int needed = vsnprintf (buf, size, fmt, ap);
00024         if (needed <= (int)size && needed >= 0) {
00025             return std::string (buf, (size_t) needed);
00026         }
00027         size = (needed > 0) ? (needed+1) : (size*2);
00028         dynamicbuf.resize (size);
00029         buf = &dynamicbuf[0];
00030     }
00031 }
00032 
00033 std::string stringex::Format (const char *fmt, ...)
00034 {
00035     va_list ap;
00036     va_start (ap, fmt);
00037     std::string buf = vformat (fmt, ap);
00038     va_end (ap);
00039     return buf;
00040 }
00041 
00042 std::string stringex::MakeUpper(string StdString)
00043 {
00044   const int length = (int)StdString.length();
00045   for(int i=0; i<length ; ++i)
00046   {
00047           StdString[i] = std::toupper(StdString[i]);
00048   }
00049   return StdString;
00050 }
00051 
00052 std::string stringex::MakeLower(string StdString)
00053 {
00054   const int length = (int)StdString.length();
00055   for(int i=0; i<length ; ++i)
00056   {
00057           StdString[i] = std::tolower(StdString[i]);
00058   }
00059   return StdString;
00060 }