| 173 | } |
| 174 | |
| 175 | MarisaDictPtr MarisaDict::NewFromBuffer(const char* data, size_t size) { |
| 176 | // Verify file header |
| 177 | size_t headerLen = strlen(OCD2_HEADER); |
| 178 | if (size < headerLen || memcmp(data, OCD2_HEADER, headerLen) != 0) { |
| 179 | throw InvalidFormat("Invalid OpenCC dictionary header"); |
| 180 | } |
| 181 | |
| 182 | size_t remainingSize = size - headerLen; |
| 183 | MarisaDictPtr dict(new MarisaDict()); |
| 184 | dict->internal->mappedBuffer.assign(data + headerLen, remainingSize); |
| 185 | |
| 186 | dict->LoadFromMappedBuffer(); |
| 187 | return dict; |
| 188 | } |
| 189 | |
| 190 | void MarisaDict::LoadFromMappedBuffer() { |
| 191 | try { |
nothing calls this directly
no test coverage detected