bool Cx_TextUtil::RemoveInvalidChars(std::wstring& text, LPCWSTR targets)
{
	std::vector<long> arrIndex;
	long i = GetSize(text);

	while (--i >= 0)
	{
		WCHAR ch = text[i];

		if (targets && IsSpaceChar(ch, targets)
			|| !targets && ((ch >= 0x0001 && ch <= 0x0008)
			|| (ch >= 0x000b && ch <= 0x000c)
			|| (ch >= 0x000e && ch <= 0x001f)
			|| (ch == 0xDBC0)) )
		{
			arrIndex.push_back(i);
		}
	}

	long nCount = GetSize(arrIndex);
	for (i = 0; i < nCount; i++)
	{
		text.erase(arrIndex[i]);
	}

	return nCount > 0;
}
bool Cx_TextUtil::TrimSpace(std::wstring& text, LPCWSTR targets)
{
	const int nOldLen = GetSize(text);
	int i = nOldLen;
	while (--i >= 0 && IsSpaceChar(text[i], targets)) {}

	if (i + 1 < nOldLen)
	{
		text.erase(text.begin() + (i + 1), text.end());
	}

	int n = GetSize(text);
	for (i = 0; i < n && IsSpaceChar(text[i], targets); i++) {}

	if (i > 0)
	{
		text.erase(text.begin(), text.begin() + i);
	}

	return nOldLen > GetSize(text);
}
bool Cx_TextUtil::TrimRight(std::wstring& text, LPCWSTR targets)
{
	const int len = GetSize(text);
	int i = len;
	while (--i >= 0 && IsSpaceChar(text[i], targets)) {}

	if (i + 1 < len)
	{
		text.erase(text.begin() + (i + 1), text.end());
	}

	return i + 1 < len;
}
bool Cx_TextUtil::TrimLeft(std::wstring& text, LPCWSTR targets)
{
	const int len = GetSize(text);
	int i = 0;

	for (; i < len && IsSpaceChar(text[i], targets); i++) {}
	if (i > 0)
	{
		text.erase(text.begin(), text.begin() + i);
	}

	return i > 0;
}
Exemple #5
0
void pgHbaConfigLine::Init(const wxString &line)
{
	connectType = PGC_INVALIDCONF;
	changed = false;

	if (line.IsEmpty())
		return;

	text = line;

	const wxChar *p0 = line.c_str();

	if (*p0 == '#')
	{
		isComment = true;
		p0++;
		SkipSpace(p0);
	}
	else
		isComment = false;


	const wxChar *p1 = p0;
	SkipNonspace(p1);

	wxString str = line.Mid(p0 - line.c_str(), p1 - p0);

	int i = FindToken(str, pgHbaConnectTypeStrings);

	if (i >= 0)
		connectType = (pgHbaConnectType)i;
	else
	{
		connectType = PGC_INVALIDCONF;
		isComment = true;
		return;
	}

	SkipSpace(p1);

	const wxChar *p2 = p1;
	bool quoted = false;

	while (*p2)
	{
		if (!quoted && IsSpaceChar(*p2))
			break;
		if (*p2 == '"')
			quoted = !quoted;
		p2++;
	}

	database = line.Mid(p1 - line.c_str(), p2 - p1);

	SkipSpace(p2);

	const wxChar *p3 = p2;

	quoted = false;
	while (*p3)
	{
		if (!quoted && IsSpaceChar(*p3))
			break;
		if (*p3 == '"')
			quoted = !quoted;
		p3++;
	}

	user = line.Mid(p2 - line.c_str(), p3 - p2);

	SkipSpace(p3);

	const wxChar *p4 = p3;

	if (connectType == PGC_LOCAL)
	{
		// no ip address
	}
	else
	{
		bool hasCidr = false;
		while (*p4 && !IsSpaceChar(*p4))
		{
			if (*p4 == '/')
				hasCidr = true;
			p4++;
		}
		if (!hasCidr)
		{
			SkipSpace(p4);
			SkipNonspace(p4);
		}

		ipaddress = line.Mid(p3 - line.c_str(), p4 - p3);
		SkipSpace(p4);
	}

	const wxChar *p5 = p4;
	SkipNonspace(p5);

	str = line.Mid(p4 - line.c_str(), p5 - p4);

	i = FindToken(str, pgHbaMethodStrings);

	if (i >= 0)
		method = (pgHbaMethod)i;
	else
	{
		connectType = PGC_INVALIDCONF;
		isComment = true;
		return;
	}
	SkipSpace(p5);
	option = p5;
}
Exemple #6
0
void SkipNonspace(const wxChar* &ptr, const wxChar *spaceChars = wxT("\t "))
{
	while (*ptr && !IsSpaceChar(*ptr))
		ptr++;
}
bool Cx_TextUtil::IsSpaceLine(const std::wstring& text)
{
	int i = GetSize(text);
	while (--i >= 0 && IsSpaceChar(text[i])) {}
	return i < 0;
}
Exemple #8
0
static void IniReadProcess(char* buf, int size)
{
	for ( int i = 0 ; i < size ; i ++ )
	{
		char	chr = buf[i];

		if ( s_bInComment )
		{
			if ( chr == '\n' || chr == '\r' )
			{
				s_bInComment = false;
			}
		}

		else if ( s_bInCommentBlock )
		{
			if ( s_cLastChar == '*' && chr == '/' )
			{
				s_bInCommentBlock = false;
			}
		}

		else
		{
			if ( s_cLastChar == '/' && chr == '/' )
			{
				s_bInComment = true;
			}
			else if ( s_cLastChar == '/' && chr == '*' )
			{
				s_bInCommentBlock = true;
			}
			else
			{
				switch ( s_iIniReadMode )
				{
				case INI_READ_READSECTION_READY:
					if ( IsValidChar(chr, false) )
					{
						s_iIniReadMode = INI_READ_READSECTION;
						s_szIniReadName[0] = chr;
						s_szIniReadName[1] = '\0';
					}
					break;

				case INI_READ_READSECTION:
					if ( IsValidChar(chr, true) )
					{
						if ( strlen(s_szIniReadName) < INIREAD_READNAME_MAX - 1 )
						{
							char	str[2];
							str[0] = chr;
							str[1] = '\0';
							strcat(s_szIniReadName, str);
						}
					}
					else if ( IsEqualChar(chr) )
					{
						s_iIniReadMode = INI_READ_READVALUE_READY;
					}
					else if ( !IsSpaceChar(chr) )
					{
						s_iIniReadMode = INI_READ_READSECTION_END;
					}
					break;

				case INI_READ_READSECTION_END:
					if ( IsEqualChar(chr) )
					{
						s_iIniReadMode = INI_READ_READVALUE_READY;
					}
					break;

				case INI_READ_READVALUE_READY:
					if ( IsValidChar(chr, true) )
					{
						s_iIniReadMode = INI_READ_READVALUE;
						s_szIniReadValue[0] = chr;
						s_szIniReadValue[1] = '\0';
					}

					if ( IsDoubleQuoteChar(chr) )
					{
						s_iIniReadMode = INI_READ_READSTRING;
						s_bInQuote = true;
						s_bBeforeYen = false;
						s_szIniReadValue[0] = '\0';
					}
					break;

				case INI_READ_READVALUE:
					if ( IsValidChar(chr, true) )
					{
						if ( strlen(s_szIniReadValue) < INIREAD_READVALUE_MAX - 1)
						{
							char	str[2];
							str[0] = chr;
							str[1] = '\0';
							strcat(s_szIniReadValue, str);
						}
					}
					else if ( IsSemiColonChar(chr) )
					{
						ReadIniSection(s_szIniReadName, s_szIniReadValue);
						s_iIniReadMode = INI_READ_READSECTION_READY;
					}
					else if ( !IsSpaceChar(chr) )
					{
						s_iIniReadMode = INI_READ_READVALUE_END;
					}
					break;

				case INI_READ_READVALUE_END:
					if ( IsEqualChar(chr) )
					{
						ReadIniSection(s_szIniReadName, s_szIniReadValue);
						s_iIniReadMode = INI_READ_READSECTION_READY;
					}
					break;

				case INI_READ_READSTRING:
					if ( !s_bBeforeYen )
					{
						if ( IsDoubleQuoteChar(chr) )
						{
							s_bInQuote = !s_bInQuote;
							break;
						}
						else if ( IsYenChar(chr) )
						{
							s_bBeforeYen = true;
							break;
						}
					}

					if ( s_bInQuote )
					{
						if ( strlen(s_szIniReadValue) < INIREAD_READVALUE_MAX - 1)
						{
							char	str[2];
							str[0] = chr;
							str[1] = '\0';
							strcat(s_szIniReadValue, str);
						}
					}
					else
					{
						if ( IsSemiColonChar(chr) )
						{
							ReadIniSectionString(s_szIniReadName, s_szIniReadValue);
							// MessageBox(0, s_szIniReadValue, s_szIniReadName, MB_OK);
							s_iIniReadMode = INI_READ_READSECTION_READY;
						}
					}
					break;
				}
			}
		}

		s_cLastChar = chr;
	}
}