Changeset 753
- Timestamp:
- 03/02/18 18:43:49 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/extvalue.cpp
r698 r753 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 748 748 SString ExtValue::formatTime(char fmt, double value) 749 749 { 750 if (fmt=='i')750 if (fmt == 'i') 751 751 { //could be Convert::ctime() 752 int d,h,m,ti=value;753 int ms=1000*(value-ti);754 d=ti/86400; ti-=d*86400;755 h=ti/3600; ti-=h*3600;756 m=ti/60; ti-=m*60;757 SString ret;758 if (d>0) ret+=SString::sprintf("%dd ",d);759 if (h>0) ret+=SString::sprintf("%d:",h);760 ret+=SString::sprintf("%02d:%02d.%03d", m,ti,ms);761 return ret;762 } 763 time_t ti = value;764 struct tm tm = Convert::localtime(ti);765 switch(fmt)752 int d, h, m, ti = value; 753 int ms = 1000 * (value - ti); 754 d = ti / 86400; ti -= d * 86400; 755 h = ti / 3600; ti -= h * 3600; 756 m = ti / 60; ti -= m * 60; 757 SString ret; 758 if (d > 0) ret += SString::sprintf("%dd ", d); 759 if (h > 0) ret += SString::sprintf("%d:", h); 760 ret += SString::sprintf("%02d:%02d.%03d", m, ti, ms); 761 return ret; 762 } 763 time_t ti = value; 764 struct tm tm = Convert::localtime(ti); 765 switch (fmt) 766 766 { 767 767 case 'T': return SString::sprintf("%04d-%02d-%02d %02d:%02d:%02d", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); 768 768 case 't': return SString(Convert::asctime(tm).c_str()); 769 769 case 'y': return SString::sprintf("%04d-%02d-%02d", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday); 770 case 'm': return SString::sprintf("%04d-%02d-%02d %02d:%02d:%02d.%03d", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, int(1000 *(value-(double)ti)));771 } 772 return SString();770 case 'm': return SString::sprintf("%04d-%02d-%02d %02d:%02d:%02d.%03d", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, int(1000 * (value - (double)ti))); 771 } 772 return SString(); 773 773 } 774 774 … … 834 834 case 't': case 'T': case 'i': case 'y': case 'm': 835 835 a = args.getNext(); 836 ret += formatTime(type, a ? a->getDouble() : 0);836 ret += formatTime(type, a ? a->getDouble() : 0); 837 837 ret += sub.substr(2); 838 838 break; … … 865 865 } 866 866 else 867 setDouble(fmod(ddata(), a));867 setDouble(fmod(ddata(), a)); 868 868 } 869 869 … … 1112 1112 tlsGetRef(ExtObject_serialization).add(o); 1113 1113 const char* p = in + 1; 1114 ExtValue tmp; 1115 while (*p) 1116 { 1117 if (isspace(*p)) p++; 1118 if (*p == ']') { p++; break; } 1114 ExtValue tmp; bool first = true, comma = false; 1115 const char* prev_element = p; 1116 while (true) 1117 { 1118 while (isspace(*p)) p++; 1119 if (*p == 0) 1120 { 1121 logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing ']' in Vector"); 1122 return NULL; 1123 } 1124 if (*p == ']') 1125 { 1126 if (comma) 1127 { 1128 logPrintf("ExtValue", "deserialize", LOG_ERROR, "No element after ',' in Vector"); 1129 return NULL; 1130 } 1131 p++; 1132 break; 1133 } 1134 if (!first && !comma) 1135 { 1136 logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing ',' in Vector: '%s'", prev_element); 1137 return NULL; 1138 } 1119 1139 ret = tmp.deserialize(p); 1140 prev_element = p; first = false; comma = false; 1120 1141 if (ret) 1121 1142 { 1122 1143 vec->data += new ExtValue(tmp); 1123 1144 p = ret; 1124 if (*p == ',') p++; 1125 else if (*p != ']') 1126 { 1127 logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing ',' in Vector: '%s'", p); 1128 return NULL; 1129 } 1145 if (*p == ',') { p++; comma = true; } 1130 1146 } 1131 1147 else … … 1145 1161 const char* p = in + 1; 1146 1162 ExtValue args[2]/*={value,key}*/, dummy_ret; 1147 while (*p) 1148 { 1149 if (isspace(*p)) p++; 1150 if (*p == '}') { p++; break; } 1163 bool first = true, comma = false; 1164 const char* prev_element = p; 1165 while (true) 1166 { 1167 while (isspace(*p)) p++; 1168 if (*p == 0) 1169 { 1170 logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing '}' in Dictionary"); 1171 return NULL; 1172 } 1173 if (*p == '}') 1174 { 1175 if (comma) 1176 { 1177 logPrintf("ExtValue", "deserialize", LOG_ERROR, "No element after ',' in Dictionary"); 1178 return NULL; 1179 } 1180 p++; 1181 break; 1182 } 1183 if (!first && !comma) 1184 { 1185 logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing ',' in Dictionary: '%s'", prev_element); 1186 return NULL; 1187 } 1151 1188 ret = args[1].deserialize(p); 1189 prev_element = p; first = false; comma = false; 1152 1190 if ((!ret) || (args[1].getType() != TString)) { p = NULL; break; } 1153 1191 p = ret; … … 1158 1196 p = ret; 1159 1197 dic->p_set(args, &dummy_ret); 1160 if (*p == ',') p++; 1161 else if (*p != '}') 1162 { 1163 logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing ',' in Dictionary: '%s'", p); 1164 return NULL; 1165 } 1198 if (*p == ',') { p++; comma = true; } 1166 1199 } 1167 1200 setObject(o);
Note: See TracChangeset
for help on using the changeset viewer.