node-sword-interface 1.0.16 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -145,7 +145,9 @@ void test_unlock_key(ModuleInstaller& module_installer, ModuleStore& module_stor
145
145
 
146
146
  void get_strongs_entry(TextProcessor& text_processor)
147
147
  {
148
- StrongsEntry* entry = text_processor.getStrongsEntry("G2766");
148
+ //StrongsEntry* entry = text_processor.getStrongsEntry("G2443");
149
+ //StrongsEntry* entry = text_processor.getStrongsEntry("G3762");
150
+ StrongsEntry* entry = text_processor.getStrongsEntry("G4572");
149
151
  if (entry != 0) {
150
152
  cout << entry->key << endl;
151
153
  cout << entry->transcription << endl;
@@ -215,7 +217,7 @@ int main(int argc, char** argv)
215
217
  /*sword_facade.installModule("StrongsHebrew");
216
218
  sword_facade.installModule("StrongsGreek");*/
217
219
 
218
- //get_strongs_entry(textProcessor);
220
+ get_strongs_entry(textProcessor);
219
221
 
220
222
  //get_module_text(textProcessor);
221
223
 
@@ -232,7 +234,7 @@ int main(int argc, char** argv)
232
234
  cout << searchResults[i].reference << endl;
233
235
  }*/
234
236
 
235
- get_updated_repo_modules(repoInterface);
237
+ //get_updated_repo_modules(repoInterface);
236
238
 
237
239
  /*get_book_headers(textProcessor);*/
238
240
 
@@ -71,10 +71,17 @@ bool StrongsReference::hasValidKey()
71
71
  return StrongsEntry::isValidStrongsKey(this->key);
72
72
  }
73
73
 
74
- StrongsEntry::StrongsEntry(string key, string rawEntry)
74
+ StrongsEntry::StrongsEntry(string key, string rawEntry, string moduleVersion)
75
75
  {
76
76
  this->key = key;
77
- this->parseFromRawEntry(rawEntry);
77
+
78
+ char moduleMinorVersion = moduleVersion[0];
79
+
80
+ if (moduleMinorVersion == '1') {
81
+ this->parseFromVersion1RawEntry(rawEntry);
82
+ } else {
83
+ this->parseFromVersion2RawEntry(rawEntry);
84
+ }
78
85
  }
79
86
 
80
87
  bool StrongsEntry::isValidStrongsKey(std::string key)
@@ -113,10 +120,13 @@ StrongsEntry* StrongsEntry::getStrongsEntry(SWModule* module, string key)
113
120
  return 0;
114
121
  }
115
122
 
123
+ string moduleVersion = module->getConfigEntry("Version");
124
+
116
125
  // Cut off the first character (H or G), since the Sword engine uses the actual number strings as the key for Strong's
117
126
  string strongsNumberString = key.substr(1);
118
127
  module->setKey(strongsNumberString.c_str());
119
- StrongsEntry* strongsEntry = new StrongsEntry(key, module->getRawEntry());
128
+
129
+ StrongsEntry* strongsEntry = new StrongsEntry(key, module->getRawEntry(), moduleVersion);
120
130
 
121
131
  return strongsEntry;
122
132
  }
@@ -165,7 +175,7 @@ void StrongsEntry::parseDefinitionAndReferences(vector<string>& lines)
165
175
 
166
176
  for (unsigned int i = 0; i < lines.size(); i++) {
167
177
  string currentLine = lines[i];
168
- if (currentLine.substr(0,5) == " see ") {
178
+ if (currentLine.substr(0,5) == " see " || currentLine.substr(0,4) == "see ") {
169
179
  StringHelper::trim(currentLine);
170
180
  StrongsReference reference(currentLine);
171
181
  // Only put the current line into the list of references if it's not already in there
@@ -193,7 +203,7 @@ void StrongsEntry::parseDefinitionAndReferences(vector<string>& lines)
193
203
  this->references = references;
194
204
  }
195
205
 
196
- void StrongsEntry::parseFromRawEntry(string rawEntry)
206
+ void StrongsEntry::parseFromVersion1RawEntry(string rawEntry)
197
207
  {
198
208
  this->rawEntry = rawEntry;
199
209
 
@@ -219,3 +229,88 @@ void StrongsEntry::parseFromRawEntry(string rawEntry)
219
229
  this->eraseEmptyLines(allLines);
220
230
  this->parseDefinitionAndReferences(allLines);
221
231
  }
232
+
233
+ void StrongsEntry::parseFromVersion2RawEntry(string rawEntry)
234
+ {
235
+ this->rawEntry = rawEntry;
236
+
237
+ cout << rawEntry << endl;
238
+
239
+ vector<string> allLines = StringHelper::split(this->rawEntry, "\n");
240
+ if (allLines.size() == 0) {
241
+ return;
242
+ }
243
+
244
+ string details = allLines[0];
245
+ string phoneticTranscription = details;
246
+
247
+ // Parse the transcription
248
+ string transcriptionTag = "<orth rend=\"bold\" type=\"trans\">";
249
+ string transcriptionEndTag = "</orth>";
250
+ this->transcription = this->parseFromVersion2Element(details, transcriptionTag, transcriptionEndTag);
251
+
252
+ // Parse the phonetic transcription
253
+ string phoneticTranscriptionTag = "<pron rend=\"italic\">{";
254
+ string phoneticTranscriptionEndTag = "}";
255
+ this->phoneticTranscription = this->parseFromVersion2Element(phoneticTranscription, phoneticTranscriptionTag, phoneticTranscriptionEndTag);
256
+
257
+ // Parse the definition
258
+ string definition = rawEntry;
259
+ definition = this->parseFromVersion2Element(rawEntry, "<def>", "</def>");
260
+ string references = definition;
261
+
262
+ std::size_t lineBreakPosition = definition.find("<lb");
263
+ string defEndTag = "</def>";
264
+ std::size_t defEndTagPosition = definition.find(defEndTag);
265
+
266
+ StringHelper::trim(definition);
267
+
268
+ string lineBreak = "<lb/>";
269
+ lineBreakPosition = definition.find(lineBreak);
270
+
271
+ if (lineBreakPosition != string::npos) {
272
+ definition.erase(lineBreakPosition, string::npos);
273
+ }
274
+
275
+ // Parse the references
276
+ lineBreakPosition = references.find(lineBreak);
277
+
278
+ if (lineBreakPosition != string::npos) {
279
+ references.erase(0, lineBreakPosition);
280
+
281
+ defEndTagPosition = references.find(defEndTag);
282
+
283
+ if (defEndTagPosition != string::npos) {
284
+ references.erase(defEndTagPosition, string::npos);
285
+ }
286
+
287
+ references.erase(0, lineBreak.size());
288
+ }
289
+
290
+ StringHelper::trim(references);
291
+ vector<string> referenceLines = StringHelper::split(references, "<lb/> ");
292
+ this->parseDefinitionAndReferences(referenceLines);
293
+
294
+ // Store definition from variable above.
295
+ this->definition = definition;
296
+ }
297
+
298
+ string StrongsEntry::parseFromVersion2Element(string rawEntry, string startTag, string endTag)
299
+ {
300
+ std::size_t startTagPosition = rawEntry.find(startTag);
301
+ if (startTagPosition != string::npos) {
302
+ rawEntry.erase(0, startTagPosition);
303
+ }
304
+
305
+ std::size_t endTagPosition = rawEntry.find(endTag);
306
+
307
+ if (endTagPosition != string::npos) {
308
+ rawEntry.erase(endTagPosition, string::npos);
309
+ }
310
+
311
+ if (startTag.size() <= rawEntry.size()) {
312
+ rawEntry.erase(0, startTag.size());
313
+ }
314
+
315
+ return rawEntry;
316
+ }
@@ -44,7 +44,7 @@ private:
44
44
  class StrongsEntry
45
45
  {
46
46
  public:
47
- StrongsEntry(std::string key, std::string rawEntry);
47
+ StrongsEntry(std::string key, std::string rawEntry, std::string moduleVersion);
48
48
  virtual ~StrongsEntry(){}
49
49
 
50
50
  static bool isValidStrongsKey(std::string key);
@@ -58,7 +58,9 @@ public:
58
58
  std::vector<StrongsReference> references;
59
59
 
60
60
  private:
61
- void parseFromRawEntry(std::string rawEntry);
61
+ void parseFromVersion1RawEntry(std::string rawEntry);
62
+ void parseFromVersion2RawEntry(std::string rawEntry);
63
+ std::string parseFromVersion2Element(std::string rawEntry, std::string startTag, std::string endTag);
62
64
  void parseFirstLine(std::string firstLine);
63
65
  void eraseEmptyLines(std::vector<std::string>& lines);
64
66
  void parseDefinitionAndReferences(std::vector<std::string>& lines);