MCPcopy Create free account
hub / github.com/creatale/node-dv / GetAvailableLanguagesAsVector

Method GetAvailableLanguagesAsVector

deps/tesseract/api/baseapi.cpp:368–412  ·  view source on GitHub ↗

* Returns the available languages in the vector of STRINGs. */

Source from the content-addressed store, hash-verified

366 * Returns the available languages in the vector of STRINGs.
367 */
368void TessBaseAPI::GetAvailableLanguagesAsVector(
369 GenericVector<STRING>* langs) const {
370 langs->clear();
371 if (tesseract_ != NULL) {
372#ifdef _WIN32
373 STRING pattern = tesseract_->datadir + "/*." + kTrainedDataSuffix;
374 char fname[_MAX_FNAME];
375 WIN32_FIND_DATA data;
376 BOOL result = TRUE;
377 HANDLE handle = FindFirstFile(pattern.string(), &data);
378 if (handle != INVALID_HANDLE_VALUE) {
379 for (; result; result = FindNextFile(handle, &data)) {
380 _splitpath(data.cFileName, NULL, NULL, fname, NULL);
381 langs->push_back(STRING(fname));
382 }
383 FindClose(handle);
384 }
385#else // _WIN32
386 DIR *dir;
387 struct dirent *dirent;
388 char *dot;
389
390 STRING extension = STRING(".") + kTrainedDataSuffix;
391
392 dir = opendir(tesseract_->datadir.string());
393 if (dir != NULL) {
394 while ((dirent = readdir(dir))) {
395 // Skip '.', '..', and hidden files
396 if (dirent->d_name[0] != '.') {
397 if (strstr(dirent->d_name, extension.string()) != NULL) {
398 dot = strrchr(dirent->d_name, '.');
399 // This ensures that .traineddata is at the end of the file name
400 if (strncmp(dot, extension.string(),
401 strlen(extension.string())) == 0) {
402 *dot = '\0';
403 langs->push_back(STRING(dirent->d_name));
404 }
405 }
406 }
407 }
408 closedir(dir);
409 }
410#endif
411 }
412}
413
414/**
415 * Init only the lang model component of Tesseract. The only functions

Callers 2

PrintLangsListFunction · 0.80

Calls 7

opendirFunction · 0.85
readdirFunction · 0.85
closedirFunction · 0.85
STRINGClass · 0.70
clearMethod · 0.45
stringMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected