Skip to content

Commit dba7f45

Browse files
authored
Merge pull request #2018 from stweil/sort
Get sorted list of available languages
2 parents f9e33e3 + d75ef80 commit dba7f45

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/api/baseapi.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* File: baseapi.cpp
33
* Description: Simple API for calling tesseract.
44
* Author: Ray Smith
5-
* Created: Fri Oct 06 15:35:01 PDT 2006
65
*
76
* (C) Copyright 2006, Google Inc.
87
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -173,6 +172,13 @@ static void addAvailableLanguages(const STRING &datadir, const STRING &base,
173172
#endif
174173
}
175174

175+
// Compare two STRING values (used for sorting).
176+
static int CompareSTRING(const void* p1, const void* p2) {
177+
const STRING* s1 = static_cast<const STRING*>(p1);
178+
const STRING* s2 = static_cast<const STRING*>(p2);
179+
return strcmp(s1->c_str(), s2->c_str());
180+
}
181+
176182
TessBaseAPI::TessBaseAPI()
177183
: tesseract_(nullptr),
178184
osd_tesseract_(nullptr),
@@ -459,13 +465,14 @@ void TessBaseAPI::GetLoadedLanguagesAsVector(
459465
}
460466

461467
/**
462-
* Returns the available languages in the vector of STRINGs.
468+
* Returns the available languages in the sorted vector of STRINGs.
463469
*/
464470
void TessBaseAPI::GetAvailableLanguagesAsVector(
465471
GenericVector<STRING>* langs) const {
466472
langs->clear();
467473
if (tesseract_ != nullptr) {
468474
addAvailableLanguages(tesseract_->datadir, "", langs);
475+
langs->sort(CompareSTRING);
469476
}
470477
}
471478

src/api/baseapi.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// File: baseapi.h
33
// Description: Simple API for calling tesseract.
44
// Author: Ray Smith
5-
// Created: Fri Oct 06 15:35:01 PDT 2006
65
//
76
// (C) Copyright 2006, Google Inc.
87
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -261,7 +260,7 @@ class TESS_API TessBaseAPI {
261260
void GetLoadedLanguagesAsVector(GenericVector<STRING>* langs) const;
262261

263262
/**
264-
* Returns the available languages in the vector of STRINGs.
263+
* Returns the available languages in the sorted vector of STRINGs.
265264
*/
266265
void GetAvailableLanguagesAsVector(GenericVector<STRING>* langs) const;
267266

0 commit comments

Comments
 (0)