1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #pragma once
- #include<string>
- #include <stdarg.h>
- using namespace std;
- static void GetNewForm(const char* form, char* newForm) {
- int indexNum = 0;
- int acount = 0;
- newForm[0] = '{';
- for (int i = 0;i < strlen(form);i++)
- {
- //if((i-1 >= 0 && form[i]=='\\') || (i-1 < 0))
- if (form[i] == '%') {
- if (acount != 0)
- {
- newForm[++indexNum] = '"';
- if (acount % 2 != 0) {
- newForm[++indexNum] = ':';
- }
- else {
- newForm[++indexNum] = ',';
- }
- }
- newForm[++indexNum] = '"';
- acount++;
- }
- if (form[i] == ' ') continue;
- newForm[++indexNum] = form[i];
- }
- newForm[++indexNum] = '"';
- newForm[++indexNum] = '}';
- }
- static string GetOutPutStr(const char* form, ...) {
- char* newForm = new char[strlen(form) * 3 + 5];
- memset(newForm, 0, strlen(form) * 3 + 5);
- if (strlen(form) < 2) {
- strcpy(newForm, "{\"\"}");
- }
- else {
- GetNewForm(form, newForm);
- }
- va_list vaList;
- va_start(vaList, form);
- int acount = _vscprintf(newForm, vaList);
- char* buf = new char[acount + 1];
- memset(buf, 0, acount + 1);
- vsprintf(buf, newForm, vaList);
- va_end(vaList);
- string ret;
- ret.assign(buf);
- delete buf;
- delete newForm;
- return ret;
- }
|