ChineseToPinyinBPLibrary.h
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Windows/AllowWindowsPlatformTypes.h"
#include "Windows/PreWindowsApi.h"
#include <wtypes.h>
#include "Windows/PostWindowsApi.h"
#include "Windows/HideWindowsPlatformTypes.h"
#include <string>
#include "ChineseToPinyinBPLibrary.generated.h"
/*
* Function library class.
* Each function in it is expected to be static and represents blueprint node that can be called in any blueprint.
*
* When declaring function you can define metadata for the node. Key function specifiers will be BlueprintPure and BlueprintCallable.
* BlueprintPure - means the function does not affect the owning object in any way and thus creates a node without Exec pins.
* BlueprintCallable - makes a function which can be executed in Blueprints - Thus it has Exec pins.
* DisplayName - full name of the node, shown when you mouse over the node and in the blueprint drop down menu.
* Its lets you name the node using characters not allowed in C++ function names.
* CompactNodeTitle - the word(s) that appear on the node.
* Keywords - the list of keywords that helps you to find node when you search for it using Blueprint drop-down menu.
* Good example is "Print String" node which you can find also by using keyword "log".
* Category - the category your node will be under in the Blueprint drop-down menu.
*
* For more info on custom blueprint nodes visit documentation:
* https://wiki.unrealengine.com/Custom_Blueprint_Node_Creation
*/
using namespace std;
UCLASS()
class UChineseToPinyinBPLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ChineseToPinyin", Keywords = "ChineseToPinyin sample test testing"), Category = "ChineseToPinyin")
static FString ChineseToPinyinSampleFunction(FString fstr);
UFUNCTION(BlueprintCallable, Category = "ChineseToPinyin")
static bool IsChinese(FString str);
private:
static char* ConvertLPWSTRToLPSTR(LPWSTR lpwszStrIn);
static int PinyinHandle(string in_str, string& out_py);
};
ChineseToPinyinBPLibrary.cpp
#include "ChineseToPinyinBPLibrary.h"
#include "ChineseToPinyin.h"
FString UChineseToPinyinBPLibrary::ChineseToPinyinSampleFunction(FString fstr)
{
char *str_name = ConvertLPWSTRToLPSTR(fstr.GetCharArray().GetData());
string in_str(str_name);
string out_py;
PinyinHandle(in_str, out_py);
FString result_py(out_py.c_str());
return result_py;
}
bool UChineseToPinyinBPLibrary::IsChinese(FString fstrName)
{
char *charName = ConvertLPWSTRToLPSTR(fstrName.GetCharArray().GetData());
string strName(charName);
for (int i=0, chrasc=0; i<strName.length(); i