Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get sorted list of available languages #2018

Merged
merged 1 commit into from
Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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