//================================================================================================== // S t a n d a r d Interface // S t r i n g // By Bruno Bachelet //================================================================================================== // Copyright (c) 1999-2016 // Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net // // This file is part of the B++ Library. This library is free software; you can redistribute it // and/or modify it under the terms of the GNU Library General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your option) any later // version. // // 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 Library General Public License for more details (http://www.gnu.org).
/*DESCRIPTION*/ /* This module provides facilities to manipulate strings of characters. */
// File Name //------------------------------------------------------------------------------------- #line __LINE__ "standard/string.hpp"
// Guardian //-------------------------------------------------------------------------------------- #ifndef guStandardString #define guStandardString
// Headers //--------------------------------------------------------------------------------------- #include <bpp/standard/memory.hpp> /*INCLUDE*/
namespace bpp {
// Importation/Exportation //----------------------------------------------------------------------- #ifdef STANDARD_DLL #define dll_export DLL_EXPORT #else #define dll_export DLL_IMPORT #endif
// Namespaces //------------------------------------------------------------------------------------ #define public_area standardString #define private_area standardString_private
namespace public_area { /*NAMESPACE*/ using namespace standardMemory; } namespace private_area { using namespace public_area; }
extern_module_name;
// Initialization //--------------------------------------------------------------------------------
// Macrocommands //---------------------------------------------------------------------------------
// Types & Classes //------------------------------------------------------------------------------- namespace public_area {}
namespace private_area { typedef tyReturn (* tyPrintStringFunction)(tyString,tcString,...); typedef tyReturn (* tyScanStringFunction)(tcString,tcString,...); }
// Functions Interface //--------------------------------------------------------------------------- namespace public_area { function tyString copy(ctString &); function tyBoolean find(tcString,tyCharacter,tyCardinal &); inline tyCharacter lastCharacter(ctString &); inline tyCharacter lastCharacter(tcString); function void replace(tyString,tyCharacter,tyCharacter); }
namespace private_area { testing_mode ( function void test(void); ) }
// Errors //---------------------------------------------------------------------------------------- namespace public_area {}
// Constants & Variables //------------------------------------------------------------------------- namespace public_area {}
// X X X Interface //------------------------------------------------------------------------------ namespace {}
// Functions Inline //------------------------------------------------------------------------------ namespace public_area { //------------------------------------------------------------------------------------LastCharacter /*FUNCTION*/ /* Returns the last character of a string. */ inline tyCharacter lastCharacter(ctString & agString) { if (agString.size()==0) return (end_string); else return (agString[agString.size()-1]); } //------------------------------------------------------------------------------------LastCharacter /*FUNCTION*/ /* Returns the last character of a string. */ inline tyCharacter lastCharacter(tcString agString) { tyCardinal lcSize = size(agString);
if (lcSize==0) return (end_string); else return (agString[lcSize-1]); } }
namespace private_area {}
// X X X Inline //--------------------------------------------------------------------------------- namespace {}
// End //------------------------------------------------------------------------------------------- } #undef dll_export #undef public_area #undef private_area #endif |
//================================================================================================== // S t a n d a r d Implementation // S t r i n g // By Bruno Bachelet //================================================================================================== // Copyright (c) 1999-2016 // Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net // // This file is part of the B++ Library. This library is free software; you can redistribute it // and/or modify it under the terms of the GNU Library General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your option) any later // version. // // 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 Library General Public License for more details (http://www.gnu.org).
// File Name //------------------------------------------------------------------------------------- #line __LINE__ "standard/string.cpp"
// DLL Belonging //--------------------------------------------------------------------------------- #define STANDARD_DLL
// Headers //--------------------------------------------------------------------------------------- #include <bpp/standard/string.hpp> /*INTERFACE*/
namespace bpp {
// Namespaces //------------------------------------------------------------------------------------ #define public_area standardString #define private_area standardString_private #define dll_export DLL_EXPORT
namespace public_area {} namespace private_area {}
static_module_name("Standard/String");
// Initialization //--------------------------------------------------------------------------------
// Errors //---------------------------------------------------------------------------------------- namespace public_area {}
// Constants & Variables //------------------------------------------------------------------------- namespace public_area {}
// Static Members //-------------------------------------------------------------------------------- namespace public_area {} namespace private_area {}
// Functions Implementation //---------------------------------------------------------------------- namespace public_area { //---------------------------------------------------------------------------------------------Copy /*FUNCTION*/ /* Copies a string. */ function tyString copy(ctString & agString) { tyString lcString = new_array(tyCharacter,agString.size()+1);
standardBasicString::copy(lcString,agString.data()); lcString[agString.size()]=end_string; return (lcString); } //------------------------------------------------------------------------------------------Replace /*FUNCTION*/ /* Replaces a character by another one into a string. */ function void replace(tyString agString,tyCharacter agOldCharacter,tyCharacter agNewCharacter) { while (*agString!=end_string) { if (*agString==agOldCharacter) *agString=agNewCharacter; agString++; } } //---------------------------------------------------------------------------------------------Find /*FUNCTION*/ /* Finds a given character in a string. <CODE>false</CODE> is returned if no character is found, else the position of the first character found is stored in the last parameter of the function. */ function tyBoolean find(tcString agString,tyCharacter agCharacter,tyCardinal & agPosition) { agPosition=0; if (agString==nil) return (false); while (agString[agPosition]!=agCharacter and agString[agPosition]!=end_string) agPosition++; return (agString[agPosition]==agCharacter); } }
namespace private_area {}
// X X X Implementation //------------------------------------------------------------------------- namespace {}
// End //------------------------------------------------------------------------------------------- } |
|