⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 api_string.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

///////////////////////////////////////////////////////////
//                                                       //
//                         SAGA                          //
//                                                       //
//      System for Automated Geoscientific Analyses      //
//                                                       //
//           Application Programming Interface           //
//                                                       //
//                  Library: SAGA_API                    //
//                                                       //
//-------------------------------------------------------//
//                                                       //
//                    api_string.cpp                     //
//                                                       //
//          Copyright (C) 2005 by Olaf Conrad            //
//                                                       //
//-------------------------------------------------------//
//                                                       //
// This file is part of 'SAGA - System for Automated     //
// Geoscientific Analyses'.                              //
//                                                       //
// This library is free software; you can redistribute   //
// it and/or modify it under the terms of the GNU Lesser //
// General Public License as published by the Free       //
// Software Foundation, version 2.1 of the License.      //
//                                                       //
// This library is distributed in the hope that it will  //
// be useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
// PARTICULAR PURPOSE. See the GNU Lesser General Public //
// License for more details.                             //
//                                                       //
// You should have received a copy of the GNU Lesser     //
// General Public License along with this program; if    //
// not, write to the Free Software Foundation, Inc.,     //
// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
// USA.                                                  //
//                                                       //
//-------------------------------------------------------//
//                                                       //
//    contact:    Olaf Conrad                            //
//                Institute of Geography                 //
//                University of Goettingen               //
//                Goldschmidtstr. 5                      //
//                37077 Goettingen                       //
//                Germany                                //
//                                                       //
//    e-mail:     oconrad@saga-gis.org                   //
//                                                       //
///////////////////////////////////////////////////////////

//---------------------------------------------------------


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#include <math.h>

#include <wx/string.h>
#include <wx/datetime.h>

#include "api_core.h"


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#define WXCONV			wxConvUTF8


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
CSG_String::CSG_String(void)
{
	m_pString	= new wxString;
#ifdef _SAGA_UNICODE
	m_bString	= NULL;
#endif
}

CSG_String::CSG_String(const CSG_String &String)
{
	m_pString	= new wxString(*String.m_pString);
#ifdef _SAGA_UNICODE
	m_bString	= NULL;
#endif
}

CSG_String::CSG_String(const SG_Char *String)
{
	m_pString	= new wxString(String);
#ifdef _SAGA_UNICODE
	m_bString	= NULL;
#endif
}

#ifdef _SAGA_UNICODE
CSG_String::CSG_String(const char *String)
{
	m_pString	= new wxString(WXCONV.cMB2WC(String));
	m_bString	= NULL;
}
#endif

CSG_String::CSG_String(SG_Char Character)
{
	m_pString	= new wxString(Character);
#ifdef _SAGA_UNICODE
	m_bString	= NULL;
#endif
}

//---------------------------------------------------------
CSG_String::~CSG_String(void)
{
	delete(m_pString);

#ifdef _SAGA_UNICODE
	if( m_bString )
	{
		SG_Free(m_bString);
	}
#endif
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
const SG_Char * CSG_String::c_str(void) const
{
	return( m_pString->c_str() );
}

//---------------------------------------------------------
#ifdef _SAGA_UNICODE
const char * CSG_String::b_str(void)
{
	m_bString	= (char *)SG_Realloc(m_bString, (1 + strlen(m_pString->mb_str(WXCONV))) * sizeof(char));

	strcpy(m_bString, m_pString->mb_str(WXCONV));

	return( m_bString );
}
#endif


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
size_t CSG_String::Length(void)	const
{
	return( m_pString->Length() );
}

//---------------------------------------------------------
void CSG_String::Clear(void)
{
	m_pString->Clear();
}

//---------------------------------------------------------
int CSG_String::Printf(const SG_Char *Format, ...)
{
	va_list	argptr;

	va_start(argptr, Format);

	m_pString->PrintfV(Format, argptr);

	va_end(argptr);

	return( Length() );
}

//---------------------------------------------------------
CSG_String CSG_String::Format(const SG_Char *Format, ...)
{
	va_list		argptr;
	CSG_String	s;

	va_start(argptr, Format);

	s.m_pString->PrintfV(Format, argptr);

	va_end(argptr);

	return( s );
}

//---------------------------------------------------------
CSG_String & CSG_String::Append(const SG_Char *String)
{
	m_pString->Append(String);

	return( *this );
}

CSG_String & CSG_String::Append(SG_Char Character)
{
	m_pString->Append(Character);

	return( *this );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
CSG_String & CSG_String::operator = (const CSG_String &String)
{
	*m_pString	= *String.m_pString;

	return( *this );
}

CSG_String & CSG_String::operator = (const SG_Char *String)
{
	*m_pString	= String;

	return( *this );
}

CSG_String & CSG_String::operator = (SG_Char Character)
{
	*m_pString	= Character;

	return( *this );
}

//---------------------------------------------------------
CSG_String CSG_String::operator + (const CSG_String &String) const
{
	CSG_String	s(*this);

	s	+= String;

	return( s );
}

CSG_String CSG_String::operator + (const SG_Char *String) const
{
	CSG_String	s(*this);

	s	+= String;

	return( s );
}

CSG_String CSG_String::operator + (SG_Char Character) const
{
	CSG_String	s(*this);

	s	+= Character;

	return( s );
}

CSG_String		operator + (const SG_Char *A, const CSG_String &B)
{
	CSG_String	s(A);

	s	+= B;

	return( s );
}

CSG_String		operator + (SG_Char A, const CSG_String &B)
{
	CSG_String	s(A);

	s	+= B;

	return( s );
}

//---------------------------------------------------------
void CSG_String::operator += (const CSG_String &String)
{
	*m_pString	+= *String.m_pString;
}

void CSG_String::operator += (const SG_Char *String)
{
	*m_pString	+= String;
}

void CSG_String::operator += (SG_Char Character)
{
	*m_pString	+= Character;
}

//---------------------------------------------------------
SG_Char & CSG_String::operator [] (int i)
{
	return( m_pString->GetWritableChar(i) );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
int CSG_String::Cmp(const SG_Char *String)	const
{
	return( m_pString->Cmp(String) );
}

//---------------------------------------------------------
int CSG_String::CmpNoCase(const SG_Char *String) const
{
	return( m_pString->CmpNoCase(String) );
}

//---------------------------------------------------------
CSG_String & CSG_String::Make_Lower(void)
{
	m_pString->MakeLower();

	return( *this );
}

//---------------------------------------------------------
CSG_String & CSG_String::Make_Upper(void)
{
	m_pString->MakeUpper();

	return( *this );
}

///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
size_t CSG_String::Replace(const SG_Char *sOld, const SG_Char *sNew, bool replaceAll)
{
	return( m_pString->Replace(sOld, sNew, replaceAll) );
}

//---------------------------------------------------------
CSG_String & CSG_String::Remove(size_t pos)
{
	m_pString->Remove(pos);

	return( *this );
}

//---------------------------------------------------------
CSG_String & CSG_String::Remove(size_t pos, size_t len)
{
	m_pString->Remove(pos, len);

	return( *this );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
int CSG_String::Remove_WhiteChars(bool fromEnd)
{
	int		n, c;

	if( fromEnd )
	{
		for(n=Length()-1; n>=0; n--)
		{
			c	= m_pString->GetChar(n);

			if( c == ' ' || c == '\t' )
			{
				break;
			}
		}

		if( n < (int)Length() - 1 )
		{
			Remove(n);
		}

		n	= Length() - n;
	}
	else
	{
		for(n=0; n<(int)Length(); n++)
		{
			c	= m_pString->GetChar(n);

			if( c == ' ' || c == '\t' )
			{
				break;
			}
		}

		if( n > 0 )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -