Skip to content

Commit

Permalink
Windows compat: use string.h, not strings.h
Browse files Browse the repository at this point in the history
Inlines the function strcasecmp from strings.h, which is
not present on Windows.

This should close Issue GregBowyer#12 and PR GregBowyer#15.
  • Loading branch information
bsolomon1124 committed Oct 8, 2019
1 parent 25452af commit c5e84d6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion bindings/encodings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
//

#include <stdio.h>
#include <strings.h>
#include <string.h> // Windows compat (vs. strings.h)
#include <ctype.h>

#include "compact_lang_det.h"
#include "encodings.h"

Expand Down Expand Up @@ -100,6 +102,19 @@ extern const cld_encoding cld_encoding_info[] = {
{"SOFTBANK_ISO_2022_JP", CLD2::SOFTBANK_ISO_2022_JP},
};

// Re-written from strings.h
inline int strcasecmp(const char *s1, const char *s2)
{
for (;;) {
int c1 = tolower( *((unsigned char *) s1++));
int c2 = tolower( *((unsigned char *) s2++));
if ((c1 != c2) || (c1 == '\0')) {
return c1 - c2;
}
}
return 0;
}

CLD2::Encoding EncodingFromName(const char *name) {
for(int i=0;i<CLD2::NUM_ENCODINGS;i++) {
if (!strcasecmp(cld_encoding_info[i].name, name)) {
Expand Down

0 comments on commit c5e84d6

Please sign in to comment.