SystemCustomizationErrcode.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include<string>
  3. #include <stdarg.h>
  4. using namespace std;
  5. static void GetNewForm(const char* form, char* newForm) {
  6. int indexNum = 0;
  7. int acount = 0;
  8. newForm[0] = '{';
  9. for (int i = 0;i < strlen(form);i++)
  10. {
  11. //if((i-1 >= 0 && form[i]=='\\') || (i-1 < 0))
  12. if (form[i] == '%') {
  13. if (acount != 0)
  14. {
  15. newForm[++indexNum] = '"';
  16. if (acount % 2 != 0) {
  17. newForm[++indexNum] = ':';
  18. }
  19. else {
  20. newForm[++indexNum] = ',';
  21. }
  22. }
  23. newForm[++indexNum] = '"';
  24. acount++;
  25. }
  26. if (form[i] == ' ') continue;
  27. newForm[++indexNum] = form[i];
  28. }
  29. newForm[++indexNum] = '"';
  30. newForm[++indexNum] = '}';
  31. }
  32. static string GetOutPutStr(const char* form, ...) {
  33. char* newForm = new char[strlen(form) * 3 + 5];
  34. memset(newForm, 0, strlen(form) * 3 + 5);
  35. if (strlen(form) < 2) {
  36. strcpy(newForm, "{\"\"}");
  37. }
  38. else {
  39. GetNewForm(form, newForm);
  40. }
  41. va_list vaList;
  42. va_start(vaList, form);
  43. int acount = _vscprintf(newForm, vaList);
  44. char* buf = new char[acount + 1];
  45. memset(buf, 0, acount + 1);
  46. vsprintf(buf, newForm, vaList);
  47. va_end(vaList);
  48. string ret;
  49. ret.assign(buf);
  50. delete buf;
  51. delete newForm;
  52. return ret;
  53. }