C++
DecodeConfigurationApiValue.hpp
#ifndef DecodeConfigurationApiValue_hpp
#define DecodeConfigurationApiValue_hpp
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
class DecodeConfigurationApiValue {
public:
void decodeConfigurationApiValue(const char *encodedString, char &buf);
};
#endif /* DecodeConfigurationApiValue_hpp */
DecodeConfigurationApiValue.cpp
#include "DecodeConfigurationApiValue.hpp"
char AscIIToChar(const char *asc)
{
int num = 0;
char buf[16] = {0};
strncpy(buf, asc, 2);
sscanf(buf, "%02X", &num);
printf("%s:%d\n", buf, num);
return num;
}
void Unescape(const char *from, unsigned long from_len, char *to, int &to_len)
{
int pos = 0;
for(int i=0; i < from_len; i++)
{
if(from[i] == '|')
{
to[pos++] = AscIIToChar(from+i+1);
i+=2;
}
else
{
to[pos++] = from[i];
}
}
to_len = pos;
}
void UNab(const char *from, unsigned long from_len, char *to, int &to_len)
{
Unescape(from, from_len, to, to_len);
to[0] = to[0] - to_len;
for (int i=1; i<to_len; i++)
{
to[i] = to[i] - to[i-1];
}
}
void DecodeConfigurationApiValue::decodeConfigurationApiValue(const char *encodedString, char &buf)
{
//const char *from="|80|DC|E8|E4|E3|ADi|5E|A6|EE|EE|A5gp|A1|D3|CA|D4|E8|A3|91|D2|DC|9C";
//char buf[2048] = {0};
int to_len = 0;
UNab(encodedString, strlen(encodedString), &buf, to_len);
printf("%s\n%d\n", &buf, to_len);
}
Objective-C
DecodeConfigurationApiValue_Wrapper.h
#ifndef DecodeConfigurationApiValue_Wrapper_h
#define DecodeConfigurationApiValue_Wrapper_h
#import <UIKit/UIKit.h>
@interface DecodeConfigurationApiValue_Wrapper : NSObject
+ (NSString *)decodeConfigurationApiValue_wrapper:(NSString *)strValue;
@end
#endif /* DecodeConfigurationApiValue_Wrapper_h */
DecodeConfigurationApiValue_Wrapper.mm
#import "DecodeConfigurationApiValue_Wrapper.h"
#include "DecodeConfigurationApiValue.hpp"
@implementation DecodeConfigurationApiValue_Wrapper
+ (NSString *)decodeConfigurationApiValue_wrapper:(NSString *)strValue {
DecodeConfigurationApiValue cpp;
char buf[2048] = {0};
cpp.decodeConfigurationApiValue([strValue cStringUsingEncoding:NSUTF8StringEncoding], *buf);
NSString *result = [NSString stringWithFormat:@"%s", buf];
return result;
}
@end
VPNOn-Bridging-Header.h
#import "DecodeConfigurationApiValue_Wrapper.h"
ConfigViewController.swift
var strQQ: String?
if let strQQ_temp = jsonConfig["QQ"].string {
strQQ = DecodeConfigurationApiValue_Wrapper.decodeConfigurationApiValue_wrapper(strQQ_temp)
if let strQQ = strQQ {
NSLog("strQQ = %@", strQQ)
} else {
NSLog("strQQ = null")
}
}