在UE4中将中文汉字转为拼音全拼

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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值