-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmapcode_legacy.c
More file actions
111 lines (94 loc) · 3.51 KB
/
mapcode_legacy.c
File metadata and controls
111 lines (94 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (C) 2014-2025 Stichting Mapcode Foundation (http://www.mapcode.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include <stdio.h>
#include "mapcode_legacy.h"
/**
* Include global legacy buffers. These are not thread-safe!
*/
static Mapcodes GLOBAL_RESULT;
static char GLOBAL_MAKEISO_BUFFER[2 * (MAX_ISOCODE_LEN + 1)];
static char* GLOBAL_MAKEISO_PTR;
int encodeLatLonToMapcodes_Deprecated(
char** mapcodesAndTerritories,
double latDeg,
double lonDeg,
enum Territory territory,
int extraDigits) {
char** v = mapcodesAndTerritories;
encodeLatLonToMapcodes(&GLOBAL_RESULT, latDeg, lonDeg, territory, extraDigits);
if (v) {
int i;
for (i = 0; i < GLOBAL_RESULT.count; i++) {
char* s = &GLOBAL_RESULT.mapcode[i][0];
char* p = strchr(s, ' ');
if (p == NULL) {
v[i * 2 + 1] = (char*)"AAA";
v[i * 2] = s;
}
else {
*p++ = 0;
v[i * 2 + 1] = s;
v[i * 2] = p;
}
}
}
return GLOBAL_RESULT.count;
}
const char* convertTerritoryCodeToIsoName_Deprecated(
enum Territory territoryContext,
int useShortName) {
if (GLOBAL_MAKEISO_PTR == GLOBAL_MAKEISO_BUFFER) {
GLOBAL_MAKEISO_PTR = GLOBAL_MAKEISO_BUFFER + (MAX_ISOCODE_LEN + 1);
}
else {
GLOBAL_MAKEISO_PTR = GLOBAL_MAKEISO_BUFFER;
}
return (const char*)getTerritoryIsoName(GLOBAL_MAKEISO_PTR, territoryContext, useShortName);
}
/**
* Include global legacy buffers. These are not thread-safe!
*/
static char GLOBAL_ASCII_BUFFER[MAX_MAPCODE_RESULT_LEN];
static UWORD GLOBAL_UTF16_BUFFER[MAX_MAPCODE_RESULT_LEN];
const char* decodeToRoman_Deprecated(const UWORD* utf16String) {
return convertToRoman(GLOBAL_ASCII_BUFFER, MAX_MAPCODE_RESULT_LEN, utf16String);
}
const UWORD* encodeToAlphabet_Deprecated(const char* asciiString,
enum Alphabet alphabet) {
return convertToAlphabet(GLOBAL_UTF16_BUFFER, MAX_MAPCODE_RESULT_LEN, asciiString, alphabet);
}
char* convertToRoman(char* asciiBuffer, int maxLength, const UWORD* unicodeBuffer) {
MapcodeElements mapcodeElements;
double lat, lon;
enum MapcodeError err;
*asciiBuffer = 0;
err = decodeMapcodeToLatLonUtf16(&lat, &lon, unicodeBuffer, TERRITORY_UNKNOWN, &mapcodeElements);
if (err == ERR_MISSING_TERRITORY || err == ERR_MAPCODE_UNDECODABLE || err == ERR_EXTENSION_UNDECODABLE) {
err = ERR_OK;
}
if (!err) {
char romanized[MAX_MAPCODE_RESULT_LEN];
sprintf(romanized, "%s%s%s%s%s",
mapcodeElements.territoryISO,
*mapcodeElements.territoryISO ? " " : "",
mapcodeElements.properMapcode,
*mapcodeElements.precisionExtension ? "-" : "",
mapcodeElements.precisionExtension);
if ((int)strlen(romanized) < maxLength) {
strcpy(asciiBuffer, romanized);
}
}
return asciiBuffer;
}