MCPcopy Create free account
hub / github.com/apple/foundationdb / LoadData

Method LoadData

fdbclient/include/fdbclient/SimpleIni.h:1250–1319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1248
1249template <class SI_CHAR, class SI_STRLESS, class SI_CONVERTER>
1250SI_Error CSimpleIniTempl<SI_CHAR, SI_STRLESS, SI_CONVERTER>::LoadData(const char* a_pData, size_t a_uDataLen) {
1251 SI_CONVERTER converter(m_bStoreIsUtf8);
1252
1253 if (a_uDataLen == 0) {
1254 return SI_OK;
1255 }
1256
1257 // consume the UTF-8 BOM if it exists
1258 if (m_bStoreIsUtf8 && a_uDataLen >= 3) {
1259 if (memcmp(a_pData, SI_UTF8_SIGNATURE, 3) == 0) {
1260 a_pData += 3;
1261 a_uDataLen -= 3;
1262 }
1263 }
1264
1265 // determine the length of the converted data
1266 size_t uLen = converter.SizeFromStore(a_pData, a_uDataLen);
1267 if (uLen == (size_t)(-1)) {
1268 return SI_FAIL;
1269 }
1270
1271 // allocate memory for the data, ensure that there is a NULL
1272 // terminator wherever the converted data ends
1273 SI_CHAR* pData = new SI_CHAR[uLen + 1];
1274 if (!pData) {
1275 return SI_NOMEM;
1276 }
1277 memset(pData, 0, sizeof(SI_CHAR) * (uLen + 1));
1278
1279 // convert the data
1280 if (!converter.ConvertFromStore(a_pData, a_uDataLen, pData, uLen)) {
1281 delete[] pData;
1282 return SI_FAIL;
1283 }
1284
1285 // parse it
1286 const static SI_CHAR empty = 0;
1287 SI_CHAR* pWork = pData;
1288 const SI_CHAR* pSection = &empty;
1289 const SI_CHAR* pItem = NULL;
1290 const SI_CHAR* pVal = NULL;
1291 const SI_CHAR* pComment = NULL;
1292
1293 // We copy the strings if we are loading data into this class when we
1294 // already have stored some.
1295 bool bCopyStrings = (m_pData != NULL);
1296
1297 // find a file comment if it exists, this is a comment that starts at the
1298 // beginning of the file and continues until the first blank line.
1299 SI_Error rc = FindFileComment(pWork, bCopyStrings);
1300 if (rc < 0)
1301 return rc;
1302
1303 // add every entry in the file to the data table
1304 while (FindEntry(pWork, pSection, pItem, pVal, pComment)) {
1305 rc = AddEntry(pSection, pItem, pVal, pComment, false, bCopyStrings);
1306 if (rc < 0)
1307 return rc;

Callers

nothing calls this directly

Calls 4

getMethod · 0.65
SizeFromStoreMethod · 0.45
ConvertFromStoreMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected