Skip to content

Commit

Permalink
Merge pull request #2018 from stweil/sort
Browse files Browse the repository at this point in the history
Get sorted list of available languages
  • Loading branch information
zdenop authored Oct 22, 2018
2 parents f9e33e3 + d75ef80 commit dba7f45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* File: baseapi.cpp
* Description: Simple API for calling tesseract.
* Author: Ray Smith
* Created: Fri Oct 06 15:35:01 PDT 2006
*
* (C) Copyright 2006, Google Inc.
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -173,6 +172,13 @@ static void addAvailableLanguages(const STRING &datadir, const STRING &base,
#endif
}

// Compare two STRING values (used for sorting).
static int CompareSTRING(const void* p1, const void* p2) {
const STRING* s1 = static_cast<const STRING*>(p1);
const STRING* s2 = static_cast<const STRING*>(p2);
return strcmp(s1->c_str(), s2->c_str());
}

TessBaseAPI::TessBaseAPI()
: tesseract_(nullptr),
osd_tesseract_(nullptr),
Expand Down Expand Up @@ -459,13 +465,14 @@ void TessBaseAPI::GetLoadedLanguagesAsVector(
}

/**
* Returns the available languages in the vector of STRINGs.
* Returns the available languages in the sorted vector of STRINGs.
*/
void TessBaseAPI::GetAvailableLanguagesAsVector(
GenericVector<STRING>* langs) const {
langs->clear();
if (tesseract_ != nullptr) {
addAvailableLanguages(tesseract_->datadir, "", langs);
langs->sort(CompareSTRING);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/api/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// File: baseapi.h
// Description: Simple API for calling tesseract.
// Author: Ray Smith
// Created: Fri Oct 06 15:35:01 PDT 2006
//
// (C) Copyright 2006, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -261,7 +260,7 @@ class TESS_API TessBaseAPI {
void GetLoadedLanguagesAsVector(GenericVector<STRING>* langs) const;

/**
* Returns the available languages in the vector of STRINGs.
* Returns the available languages in the sorted vector of STRINGs.
*/
void GetAvailableLanguagesAsVector(GenericVector<STRING>* langs) const;

Expand Down

0 comments on commit dba7f45

Please sign in to comment.