All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ukrainiantolatin.res.UkrainianToLatin.cpp Maven / Gradle / Ivy

#include "UkrainianToLatin.h"

namespace com
{
	namespace github
	{
		namespace ukrainiantolatin
		{

			UkrainianToLatin::ConvertCase::ConvertCase(Convert convert, bool lowcase) : convert(convert), lowcase(lowcase)
			{
			}

			com::github::ukrainiantolatin::UkrainianToLatin::Convert UkrainianToLatin::ConvertCase::getConvert()
			{
				return convert;
			}

			bool UkrainianToLatin::ConvertCase::isLowcase()
			{
				return lowcase;
			}

//JAVA TO C++ CONVERTER TODO TASK: Static constructors are not allowed in native C++:
			UkrainianToLatin::UkrainianToLatin()
			{
				cyrToLat = std::unordered_map();
				for (Convert convert : Convert::values())
				{
					cyrToLat->put(convert.getCyrilic()->substr(INDEX_0, INDEX_1 - INDEX_0), new ConvertCase(convert, false));
					cyrToLat->put(convert.getCyrilic()->substr(INDEX_1, INDEX_2 - INDEX_1), new ConvertCase(convert, true));
					if (convert == Convert::EE)
					{
						cyrToLat->put(L"Ё", new ConvertCase(convert, false));
						cyrToLat->put(L"ё", new ConvertCase(convert, true));
					}
				}
			}

			std::wstring UkrainianToLatin::generateLat(const std::wstring &name)
			{
				StringBuffer *result = new StringBuffer();
				ConvertCase *prevConvertCase = nullptr;
				for (int index = 0; index < name.length(); index += 1)
				{
					std::wstring curChar = name.substr(index, INDEX_1);
					std::wstring nextChar = index == name.length() - 1 ? nullptr : name.substr(index + INDEX_1, index + INDEX_2 - (index + INDEX_1));
//JAVA TO C++ CONVERTER NOTE: Add an include for #include  or use std::regex_match and add #include  for C++11:
					if (boost::regex_match(curChar, boost::regex(L"[-'’,]")))
					{
						continue;
					}
					if (cyrToLat->get(curChar) == nullptr)
					{
						if ((std::wstring(L" ")) == curChar)
						{
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
							delete prevConvertCase;
							result->append(L' ');
						}
//JAVA TO C++ CONVERTER NOTE: Add an include for #include  or use std::regex_match and add #include  for C++11:
						else if (boost::regex_match(curChar, boost::regex(L"\\n")))
						{
							result->append(curChar);
						}
						continue;
					}
					ConvertCase *convertCase = cyrToLat->get(curChar);
					if (prevConvertCase == nullptr)
					{
						checkFirstChar(result, convertCase, cyrToLat->get(nextChar) == nullptr ? convertCase : cyrToLat->get(nextChar));
					}
					else
					{
						checkMiddleChar(result, convertCase, cyrToLat->get(nextChar) == nullptr ? convertCase : cyrToLat->get(nextChar));
					}
					prevConvertCase = convertCase;
				}
//JAVA TO C++ CONVERTER TODO TASK: There is no native C++ equivalent to 'toString':
				return result->toString();
			}

			void UkrainianToLatin::checkFirstChar(StringBuffer *result, ConvertCase *convertCase, ConvertCase *nextConvertCase)
			{
				std::wstring latName = convertCase->getConvert()::name();
				switch (latName.length())
				{
				case LENGTH_2:
					result->append(convertCase->isLowcase() ? latName.substr(INDEX_0, INDEX_1 - INDEX_0)->toLowerCase() : nextConvertCase->isLowcase() ? latName.substr(INDEX_0, INDEX_1 - INDEX_0) : latName.substr(INDEX_0, INDEX_1 - INDEX_0)->toUpperCase());
					if (convertCase->getConvert() == Convert::ZZ && nextConvertCase->getConvert() == Convert::HH)
					{
						result->append(nextConvertCase->isLowcase() ? L"g" : L"G");
					}
					break;
				case LENGTH_3:
				case LENGTH_4:
					result->append(convertCase->isLowcase() ? latName.substr(INDEX_0, INDEX_2 - INDEX_0)->toLowerCase() : nextConvertCase->isLowcase() ? latName.substr(INDEX_0, INDEX_2 - INDEX_0) : latName.substr(INDEX_0, INDEX_2 - INDEX_0)->toUpperCase());
					break;
				case LENGTH_8:
					result->append(convertCase->isLowcase() ? latName.substr(INDEX_0, INDEX_4 - INDEX_0)->toLowerCase() : nextConvertCase->isLowcase() ? latName.substr(INDEX_0, INDEX_4 - INDEX_0) : latName.substr(INDEX_0, INDEX_4 - INDEX_0)->toUpperCase());
					break;
				default:
					break;
				}
			}

			void UkrainianToLatin::checkMiddleChar(StringBuffer *result, ConvertCase *convertCase, ConvertCase *nextConvertCase)
			{
				std::wstring latName = convertCase->getConvert()::name();
				switch (latName.length())
				{
				case LENGTH_2:
					result->append(convertCase->isLowcase() ? latName.substr(INDEX_1, INDEX_2 - INDEX_1)->toLowerCase() : nextConvertCase->isLowcase() ? latName.substr(INDEX_1, INDEX_2 - INDEX_1) : latName.substr(INDEX_1, INDEX_2 - INDEX_1)->toUpperCase());
					if (convertCase->getConvert() == Convert::ZZ && nextConvertCase->getConvert() == Convert::HH)
					{
						result->append(nextConvertCase->isLowcase() ? L"g" : L"G");
					}
					break;
				case LENGTH_3:
					result->append(convertCase->isLowcase() ? latName.substr(INDEX_2, INDEX_3 - INDEX_2)->toLowerCase() : nextConvertCase->isLowcase() ? latName.substr(INDEX_2, INDEX_3 - INDEX_2) : latName.substr(INDEX_2, INDEX_3 - INDEX_2)->toUpperCase());
					break;
				case LENGTH_4:
					result->append(convertCase->isLowcase() ? latName.substr(INDEX_2, INDEX_4 - INDEX_2)->toLowerCase() : nextConvertCase->isLowcase() ? latName.substr(INDEX_2, INDEX_4 - INDEX_2) : latName.substr(INDEX_2, INDEX_4 - INDEX_2)->toUpperCase());
					break;
				case LENGTH_8:
					result->append(convertCase->isLowcase() ? latName.substr(INDEX_4, INDEX_8 - INDEX_4)->toLowerCase() : nextConvertCase->isLowcase() ? latName.substr(INDEX_4, INDEX_8 - INDEX_4) : latName.substr(INDEX_4, INDEX_8 - INDEX_4)->toUpperCase());
					break;
				default:
					break;
				}
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy