Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Util SP - String.h
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
#if !defined(TGS_COMMON_UTIL_SP_STRING_H)
#define TGS_COMMON_UTIL_SP_STRING_H
#pragma once


/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Types                                                                                                                                                          */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#if defined(TgCOMPILE_WIDE_CHAR)
enum { KTgSTRING_STATIC_BUFFER_SIZE             = 12 };
#else
enum { KTgSTRING_STATIC_BUFFER_SIZE             = 16 };
#endif

TgTYPE_STRUCT(STg2_UTS_ST,)
{
    union
    {
        TgCHAR                                      m_aBuffer[KTgSTRING_STATIC_BUFFER_SIZE];
        CP_TgCHAR                                   m_pszSrc;
        P_TgCHAR                                    m_pszDest;
    }                                           m_unData;
    TgSIZE                                      m_uiBuffer;
    TgSIZE                                      m_uiReserve;
};
TgCOMPILER_ASSERT( sizeof( STg2_UTS_ST ) == 32, 0 );


/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

TgINLINE TgVOID                             tgCM_UTS_ST_Init( PC_STg2_UTS_ST );
TgINLINE TgVOID                             tgCM_UTS_ST_Free( PC_STg2_UTS_ST );


                                            /* Init */

TgINLINE TgVOID                             tgCM_UTS_ST_CH_Init( PC_STg2_UTS_ST, C_TgSIZE, C_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_SZ_Init( PC_STg2_UTS_ST, CPC_TgCHAR );
TgINLINE TgVOID                             tgCM_UTS_ST_SN_Init( PC_STg2_UTS_ST, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgVOID                             tgCM_UTS_ST_PT_Init( PC_STg2_UTS_ST, CPC_TgCHAR, CPC_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_ST_Init( PC_STg2_UTS_ST, CPC_STg2_UTS_ST );
TgINLINE TgVOID                             tgCM_UTS_ST_SO_Init( PC_STg2_UTS_ST, CPC_STg2_UTS_ST, C_TgSIZE );
TgINLINE TgVOID                             tgCM_UTS_ST_SF_Init( PC_STg2_UTS_ST, CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE );


                                            /* Assign */

TgEXTN TgVOID                               tgCM_UTS_ST_CH_Assign( PC_STg2_UTS_ST, C_TgSIZE, C_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_SZ_Assign( PC_STg2_UTS_ST, CPC_TgCHAR );
TgINLINE TgVOID                             tgCM_UTS_ST_SN_Assign( PC_STg2_UTS_ST, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgVOID                             tgCM_UTS_ST_PT_Assign( PC_STg2_UTS_ST, CPC_TgCHAR, CPC_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_ST_Assign( PC_STg2_UTS_ST, CPC_STg2_UTS_ST );
TgINLINE TgVOID                             tgCM_UTS_ST_SO_Assign( PC_STg2_UTS_ST, CPC_STg2_UTS_ST, C_TgSIZE );
TgEXTN TgVOID                               tgCM_UTS_ST_SF_Assign( PC_STg2_UTS_ST, CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE );


                                            /* Append */

TgEXTN TgVOID                               tgCM_UTS_ST_CH_Append( PC_STg2_UTS_ST, C_TgSIZE, C_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_SZ_Append( PC_STg2_UTS_ST, CPC_TgCHAR );
TgINLINE TgVOID                             tgCM_UTS_ST_SN_Append( PC_STg2_UTS_ST, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgVOID                             tgCM_UTS_ST_PT_Append( PC_STg2_UTS_ST, CPC_TgCHAR, CPC_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_ST_Append( PC_STg2_UTS_ST, CPC_STg2_UTS_ST );
TgINLINE TgVOID                             tgCM_UTS_ST_SO_Append( PC_STg2_UTS_ST, CPC_STg2_UTS_ST, C_TgSIZE );
TgEXTN TgVOID                               tgCM_UTS_ST_SF_Append( PC_STg2_UTS_ST, CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE );


                                            /* Insert */

TgEXTN TgVOID                               tgCM_UTS_ST_CH_Insert( PC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, C_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_SZ_Insert( PC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR );
TgINLINE TgVOID                             tgCM_UTS_ST_SN_Insert( PC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgVOID                             tgCM_UTS_ST_PT_Insert( PC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR, CPC_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_ST_Insert( PC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST );
TgINLINE TgVOID                             tgCM_UTS_ST_SO_Insert( PC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST, C_TgSIZE );
TgEXTN TgVOID                               tgCM_UTS_ST_SF_Insert( PC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE );


                                            /* Replace */

TgEXTN TgVOID                               tgCM_UTS_ST_CH_Replace( PC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, C_TgSIZE, C_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_SZ_Replace( PC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_TgCHAR );
TgINLINE TgVOID                             tgCM_UTS_ST_SN_Replace( PC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgVOID                             tgCM_UTS_ST_RN_Replace( PC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_TgCHAR, CPC_TgCHAR );

TgINLINE TgVOID                             tgCM_UTS_ST_ST_Replace( PC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_STg2_UTS_ST );
TgINLINE TgVOID                             tgCM_UTS_ST_SO_Replace( PC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_STg2_UTS_ST, C_TgSIZE );
TgEXTN TgVOID                               tgCM_UTS_ST_SF_Replace( PC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE );


                                            /* Miscellaneous */

TgEXTN TgVOID                               tgCM_UTS_SF_Erase( PC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE );
TgINLINE TgVOID                             tgCM_UTS_ST_Clear( PC_STg2_UTS_ST );

TgINLINE TgVOID                             tgCM_UTS_ST_To_Upper( PC_STg2_UTS_ST );
TgINLINE TgVOID                             tgCM_UTS_ST_To_Lower( PC_STg2_UTS_ST );

TgINLINE TgVOID                             tgCM_UTS_ST_Format( PC_STg2_UTS_ST, CPC_TgCHAR, ... );

TgINLINE CP_TgCHAR                          tgCM_UTS_ST_Query_String( CPC_STg2_UTS_ST );
TgINLINE TgBOOL                             tgCM_UTS_ST_Is_Empty( CPC_STg2_UTS_ST );
TgINLINE TgSIZE                             tgCM_UTS_ST_Capacity( CPC_STg2_UTS_ST );
TgINLINE TgSIZE                             tgCM_UTS_ST_Size( CPC_STg2_UTS_ST ); /*« not including the null terminator */
TgINLINE TgSIZE                             tgCM_UTS_ST_Max_size( CPC_STg2_UTS_ST );
TgINLINE TgSIZE                             tgCM_UTS_ST_Length( CPC_STg2_UTS_ST ); /*« not including the null terminator */

TgEXTN TgVOID                               tgCM_UTS_ST_Resize( PC_STg2_UTS_ST, C_TgSIZE, C_TgCHAR );
TgINLINE TgVOID                             tgCM_UTS_ST_Reserve( PC_STg2_UTS_ST, C_TgSIZE );

TgINLINE TgVOID                             tgCM_UTS_ST_Swap( PC_STg2_UTS_ST, PC_STg2_UTS_ST );

TgINLINE TgBOOL                             tgCM_UTS_ST_Is_Inside( CPC_STg2_UTS_ST, CPC_TgCHAR );


                                            /* Compare */

TgINLINE TgSINT32                           tgCM_UTS_ST_ST_Compare( CPC_STg2_UTS_ST, CPC_STg2_UTS_ST );
TgINLINE TgSINT32                           tgCM_UTS_SF_ST_Compare( CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_STg2_UTS_ST );
TgINLINE TgSINT32                           tgCM_UTS_SF_SF_Compare( CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE );

TgINLINE TgSINT32                           tgCM_UTS_ST_SZ_Compare( CPC_STg2_UTS_ST, CPC_TgCHAR );
TgINLINE TgSINT32                           tgCM_UTS_SF_SZ_Compare( CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_TgCHAR );
TgINLINE TgSINT32                           tgCM_UTS_SF_SN_Compare( CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE, CPC_TgCHAR, C_TgSIZE );


                                            /* Find */

TgINLINE TgSIZE                             tgCM_UTS_SO_ST_Find_String( CPC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST );
TgEXTN TgSIZE                               tgCM_UTS_SO_SF_Find_String( CPC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE );
TgINLINE TgSIZE                             tgCM_UTS_SO_SZ_Find_String( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR );
TgINLINE TgSIZE                             tgCM_UTS_SO_SN_Find_String( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR, C_TgSIZE );

TgINLINE TgSIZE                             tgCM_UTS_SO_ST_Find_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST );
TgINLINE TgSIZE                             tgCM_UTS_SO_SZ_Find_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR );
TgINLINE TgSIZE                             tgCM_UTS_SO_SN_Find_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgSIZE                             tgCM_UTS_SO_Find_Char( CPC_STg2_UTS_ST, C_TgSIZE, C_TgCHAR );

TgINLINE TgSIZE                             tgCM_UTS_SO_ST_Find_Not_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST );
TgINLINE TgSIZE                             tgCM_UTS_SO_SZ_Find_Not_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR );
TgINLINE TgSIZE                             tgCM_UTS_SO_SN_Find_Not_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgSIZE                             tgCM_UTS_SO_Find_Not_Char( CPC_STg2_UTS_ST, C_TgSIZE, C_TgCHAR );


                                            /* RFind */

TgINLINE TgSIZE                             tgCM_UTS_SO_ST_RFind_String( CPC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST );
TgEXTN TgSIZE                               tgCM_UTS_SO_SF_RFind_String( CPC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST, C_TgSIZE, C_TgSIZE );
TgINLINE TgSIZE                             tgCM_UTS_SO_SZ_RFind_String( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR );
TgINLINE TgSIZE                             tgCM_UTS_SO_SN_RFind_String( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR, C_TgSIZE );

TgINLINE TgSIZE                             tgCM_UTS_SO_ST_RFind_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST );
TgINLINE TgSIZE                             tgCM_UTS_SO_SZ_RFind_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR );
TgINLINE TgSIZE                             tgCM_UTS_SO_SN_RFind_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgSIZE                             tgCM_UTS_SO_RFind_Char( CPC_STg2_UTS_ST, C_TgSIZE, C_TgCHAR );

TgINLINE TgSIZE                             tgCM_UTS_SO_ST_RFind_Not_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_STg2_UTS_ST );
TgINLINE TgSIZE                             tgCM_UTS_SO_SZ_RFind_Not_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR );
TgINLINE TgSIZE                             tgCM_UTS_SO_SN_RFind_Not_Set( CPC_STg2_UTS_ST, C_TgSIZE, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgSIZE                             tgCM_UTS_SO_RFind_Not_Char( CPC_STg2_UTS_ST, C_TgSIZE, C_TgCHAR );


                                            /* Trim */

TgINLINE TgVOID                             tgCM_UTS_ST_Trim_Start_Char( PC_STg2_UTS_ST, C_TgCHAR );
TgINLINE TgVOID                             tgCM_UTS_ST_Trim_Start_Set( PC_STg2_UTS_ST, CPC_TgCHAR, C_TgSIZE );
TgINLINE TgVOID                             tgCM_UTS_ST_Trim_End_Char( PC_STg2_UTS_ST, C_TgCHAR );
TgINLINE TgVOID                             tgCM_UTS_ST_Trim_End_Set( PC_STg2_UTS_ST, CPC_TgCHAR, C_TgSIZE );


/* ====================================================================================================================================================================== */
#endif