-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.cpp
66 lines (56 loc) · 1.98 KB
/
library.cpp
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
//
// Created by Sergey Zinchenko on 07.01.17.
// Copyright © 2017 SMediaLink. All rights reserved.
//
#include <mysql.h>
#include <my_global.h>
#include <codecvt>
#include <functional>
#include <locale>
#include <algorithm>
#include "algo.h"
#include "ertranslit.h"
#ifdef __cplusplus
extern "C" {
#endif
my_bool zinshtein_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {
if (args->arg_count < 2) {
strcpy(message, "ZINSHTEIN() requires two or more arguments");
return 1;
}
for (long i = 0; i < args->arg_count; i++) {
if (args->arg_type[i] != STRING_RESULT) {
strcpy(message, "ZINSHTEIN() requires only string arguments");
return 1;
}
}
if (args->args[args->arg_count - 1] == NULL) {
strcpy(message, "ZINSHTEIN() requires last one argument not to be null");
return 1;
}
initid->max_length = 3;
initid->maybe_null = 0;
return 0;
}
longlong zinshtein(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) {
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::wstring str1 = L"";
for (long i = 0; i < args->arg_count - 1; i++) {
if (args->args[i] != NULL)
str1 += converter.from_bytes(args->args[i]);
}
std::wstring str2 = converter.from_bytes(args->args[args->arg_count - 1]);
str1.erase(std::remove_if(str1.begin(), str1.end(), ::isspace), str1.end());
//std::transform(str1.begin(), str1.end(), str1.begin(), std::bind2nd(std::ptr_fun(&std::tolower<wchar_t>), std::locale("")));
str2.erase(std::remove_if(str2.begin(), str2.end(), ::isspace), str2.end());
//std::transform(str2.begin(), str2.end(), str2.begin(), std::bind2nd(std::ptr_fun(&std::tolower<wchar_t>), std::locale("")));
return zinshtein(&str1, &str2);
// std::wstring *ps1 = retranslit(&str1), *ps2 = retranslit(&str2);
// longlong result = zinshtein(ps1, ps2);
// delete ps1;
// delete ps2;
// return result;
}
#ifdef __cplusplus
}
#endif