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