Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Util SP - String.inl
    »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_INL)
#define TGS_COMMON_UTIL_SP_STRING_INL
#pragma once


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

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

/* ---- tgCM_UTM_AM_ST_Init --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Init( PC_STg2_UTS_ST psDest )
{
    psDest->m_uiReserve = KTgSTRING_STATIC_BUFFER_SIZE;
    psDest->m_uiBuffer = 0;
    psDest->m_unData.m_aBuffer[0] = TgT('\0');
}


/* ---- tgCM_UTS_ST_Free ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Free( PC_STg2_UTS_ST psDest )
{
    tgCM_UTS_ST_Clear( psDest );
}


/* ---- tgCM_UTS_ST_CH_Init --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_CH_Init( PC_STg2_UTS_ST psDest, C_TgSIZE uiCount, C_TgCHAR uiChar )
{
    tgCM_UTS_ST_Init( psDest );
    tgCM_UTS_ST_CH_Assign( psDest, uiCount, uiChar );
}


/* ---- tgCM_UTS_ST_SZ_Init --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SZ_Init( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszStart )
{
    tgCM_UTS_ST_Init( psDest );

    if (TgEXPECT_TRUE( nullptr != pszStart ))
    {
        tgCM_UTS_ST_SZ_Assign( psDest, pszStart );
    }
}


/* ---- tgCM_UTS_ST_SN_Init --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SN_Init( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszStart, C_TgSIZE uiLength )
{
    tgCM_UTS_ST_Init( psDest );

    if (TgEXPECT_TRUE( nullptr != pszStart ))
    {
        tgCM_UTS_ST_SN_Assign( psDest, pszStart, uiLength );
    }
}


/* ---- tgCM_UTS_ST_PT_Init --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_PT_Init( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszStart, CPC_TgCHAR pszLast )
{
    tgCM_UTS_ST_Init( psDest );

    if (TgEXPECT_TRUE( nullptr != pszStart ))
    {
        tgCM_UTS_ST_PT_Assign( psDest, pszStart, pszLast );
    }
}


/* ---- tgCM_UTS_ST_ST_Init --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_ST_Init( PC_STg2_UTS_ST psDest, CPC_STg2_UTS_ST psSrc )
{
    tgCM_UTS_ST_Init( psDest );

    if (TgEXPECT_TRUE( nullptr != psSrc ))
    {
        tgCM_UTS_ST_ST_Assign( psDest, psSrc );
    }
}


/* ---- tgCM_UTS_ST_SO_Init --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SO_Init( PC_STg2_UTS_ST psDest, CPC_STg2_UTS_ST psSrc, C_TgSIZE uiOffset )
{
    tgCM_UTS_ST_Init( psDest );

    if (TgEXPECT_TRUE( nullptr != psSrc ))
    {
        tgCM_UTS_ST_SO_Assign( psDest, psSrc, uiOffset );
    }
}


/* ---- tgCM_UTS_ST_SF_Init --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SF_Init( PC_STg2_UTS_ST psDest, CPC_STg2_UTS_ST psSrc, C_TgSIZE uiOffset, C_TgSIZE uiLength )
{
    tgCM_UTS_ST_Init( psDest );

    if (TgEXPECT_TRUE( nullptr != psSrc ))
    {
        tgCM_UTS_ST_SF_Assign( psDest, psSrc, uiOffset, uiLength );
    }
}


/* ---- tgCM_UTS_ST_SZ_Assign ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SZ_Assign( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszSrc )
{
    if (TgEXPECT_FALSE( nullptr == pszSrc ))
    {
        tgCM_UTS_ST_Clear( psDest );
    }
    else
    {
        STg2_UTS_ST                       tgSrc;

        tgSrc.m_unData.m_pszSrc = pszSrc;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Assign( psDest, &tgSrc, 0, KTgMAX_SIZE );
    };
}


/* ---- tgCM_UTS_ST_SN_Assign ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SN_Assign( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszSrc, C_TgSIZE uiLength )
{
    if (TgEXPECT_FALSE( nullptr == pszSrc ))
    {
        tgCM_UTS_ST_Clear( psDest );
    }
    else
    {
        STg2_UTS_ST                       tgSrc;

        tgSrc.m_unData.m_pszSrc = pszSrc;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Assign( psDest, &tgSrc, 0, uiLength );
    };
}


/* ---- tgCM_UTS_ST_PT_Assign ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_PT_Assign( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszSrc_Start, CPC_TgCHAR pszSrc_End )
{
    if (TgEXPECT_FALSE( nullptr == pszSrc_Start || nullptr == pszSrc_End || pszSrc_End <= pszSrc_Start ))
    {
        tgCM_UTS_ST_Clear( psDest );
    }
    else
    {
        STg2_UTS_ST                       tgSrc;

        TgERROR((TgSIZE)(pszSrc_End - pszSrc_Start) < KTgMAX_U32);

        tgSrc.m_unData.m_pszSrc = pszSrc_Start;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc_Start );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Assign( psDest, &tgSrc, 0, (TgSIZE)(pszSrc_End - pszSrc_Start) );
    };
}


/* ---- tgCM_UTS_ST_ST_Assign ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_ST_Assign( PC_STg2_UTS_ST psDest, CPC_STg2_UTS_ST psSrc )
{
    tgCM_UTS_ST_SF_Assign( psDest, psSrc, 0, KTgMAX_SIZE );
}


/* ---- tgCM_UTS_ST_SO_Assign ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SO_Assign( PC_STg2_UTS_ST psDest, CPC_STg2_UTS_ST psSrc, C_TgSIZE uiOffset )
{
    tgCM_UTS_ST_SF_Assign( psDest, psSrc, uiOffset, KTgMAX_SIZE );
}


/* ---- tgCM_UTS_ST_SZ_Append ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SZ_Append( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszSrc )
{
    if (TgEXPECT_TRUE( nullptr != pszSrc ))
    {
        STg2_UTS_ST                       tgSrc;

        tgSrc.m_unData.m_pszSrc = pszSrc;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Append( psDest, &tgSrc, 0, KTgMAX_SIZE );
    };
}


/* ---- tgCM_UTS_ST_SN_Append ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SN_Append( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszSrc, C_TgSIZE uiLength )
{
    if (TgEXPECT_TRUE( nullptr != pszSrc ))
    {
        STg2_UTS_ST                       tgSrc;

        tgSrc.m_unData.m_pszSrc = pszSrc;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Append( psDest, &tgSrc, 0, uiLength );
    };
}


/* ---- tgCM_UTS_ST_PT_Append ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_PT_Append( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszSrc_Start, CPC_TgCHAR pszSrc_End )
{
    if (TgEXPECT_TRUE( !(nullptr == pszSrc_Start || nullptr == pszSrc_End || pszSrc_End <= pszSrc_Start) ))
    {
        STg2_UTS_ST                       tgSrc;

        TgERROR((TgSIZE)(pszSrc_End - pszSrc_Start) < KTgMAX_U32);

        tgSrc.m_unData.m_pszSrc = pszSrc_Start;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc_Start );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Append( psDest, &tgSrc, 0, (TgSIZE)(pszSrc_End - pszSrc_Start) );
    };
}


/* ---- tgCM_UTS_ST_ST_Append ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_ST_Append( PC_STg2_UTS_ST psDest, CPC_STg2_UTS_ST psSrc )
{
    tgCM_UTS_ST_SF_Append( psDest, psSrc, 0, KTgMAX_SIZE );
}


/* ---- tgCM_UTS_ST_SO_Append ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SO_Append( PC_STg2_UTS_ST psDest, CPC_STg2_UTS_ST psSrc, C_TgSIZE uiOffset )
{
    tgCM_UTS_ST_SF_Append( psDest, psSrc, uiOffset, KTgMAX_SIZE );
}


/* ---- tgCM_UTS_ST_SZ_Insert ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SZ_Insert( PC_STg2_UTS_ST psDest, C_TgSIZE uiIdx, CPC_TgCHAR pszSrc )
{
    if (TgEXPECT_TRUE( nullptr != pszSrc ))
    {
        STg2_UTS_ST                       tgSrc;

        tgSrc.m_unData.m_pszSrc = pszSrc;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Insert( psDest, uiIdx, &tgSrc, 0, KTgMAX_SIZE );
    };
}


/* ---- tgCM_UTS_ST_SN_Insert ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SN_Insert( PC_STg2_UTS_ST psDest, C_TgSIZE uiIdx, CPC_TgCHAR pszSrc, C_TgSIZE uiLength )
{
    if (TgEXPECT_TRUE( nullptr != pszSrc ))
    {
        STg2_UTS_ST                       tgSrc;

        tgSrc.m_unData.m_pszSrc = pszSrc;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Insert( psDest, uiIdx, &tgSrc, 0, uiLength );
    };
}


/* ---- tgCM_UTS_ST_PT_Insert ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_PT_Insert( PC_STg2_UTS_ST psDest, C_TgSIZE uiIdx, CPC_TgCHAR pszSrc_Start, CPC_TgCHAR pszSrc_End )
{
    if (TgEXPECT_TRUE( !(nullptr == pszSrc_Start || nullptr == pszSrc_End || pszSrc_End <= pszSrc_Start) ))
    {
        STg2_UTS_ST                       tgSrc;

        TgERROR((TgSIZE)(pszSrc_End - pszSrc_Start) < KTgMAX_U32);

        tgSrc.m_unData.m_pszSrc = pszSrc_Start;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc_Start );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Insert( psDest, uiIdx, &tgSrc, 0, (TgSIZE)(pszSrc_End - pszSrc_Start) );
    };
}


/* ---- tgCM_UTS_ST_ST_Insert ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_ST_Insert( PC_STg2_UTS_ST psDest, C_TgSIZE uiIdx, CPC_STg2_UTS_ST psSrc )
{
    tgCM_UTS_ST_SF_Insert( psDest, uiIdx, psSrc, 0, KTgMAX_SIZE );
}


/* ---- tgCM_UTS_ST_SO_Insert ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SO_Insert( PC_STg2_UTS_ST psDest, C_TgSIZE uiIdx, CPC_STg2_UTS_ST psSrc, C_TgSIZE uiOffset )
{
    tgCM_UTS_ST_SF_Insert( psDest, uiIdx, psSrc, uiOffset, KTgMAX_SIZE );
}


/* ---- tgCM_UTS_ST_SZ_Replace ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SZ_Replace( PC_STg2_UTS_ST psDest, C_TgSIZE uiStart, C_TgSIZE uiEnd, CPC_TgCHAR pszSrc )
{
    if (TgEXPECT_TRUE( nullptr != pszSrc ))
    {
        STg2_UTS_ST                       tgSrc;

        tgSrc.m_unData.m_pszSrc = pszSrc;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Replace( psDest, uiStart, uiEnd, &tgSrc, 0, KTgMAX_SIZE );
    }
    else
    {
        tgCM_UTS_SF_Erase( psDest, uiStart, uiEnd - uiStart );
    };
}


/* ---- tgCM_UTS_ST_SN_Replace ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SN_Replace( PC_STg2_UTS_ST psDest, C_TgSIZE uiStart, C_TgSIZE uiEnd, CPC_TgCHAR pszSrc, C_TgSIZE uiLength )
{
    if (TgEXPECT_TRUE( nullptr != pszSrc ))
    {
        STg2_UTS_ST                       tgSrc;

        tgSrc.m_unData.m_pszSrc = pszSrc;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Replace( psDest, uiStart, uiEnd, &tgSrc, 0, uiLength );
    }
    else
    {
        tgCM_UTS_SF_Erase( psDest, uiStart, uiEnd - uiStart );
    };
}


/* ---- tgCM_UTS_ST_RN_Replace ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_RN_Replace( PC_STg2_UTS_ST psDest, C_TgSIZE uiStart, C_TgSIZE uiEnd, CPC_TgCHAR pszSrc_Start, CPC_TgCHAR pszSrc_End )
{
    if (TgEXPECT_TRUE( !(nullptr == pszSrc_Start || nullptr == pszSrc_End || pszSrc_End <= pszSrc_Start) ))
    {
        STg2_UTS_ST                       tgSrc;

        TgERROR((TgSIZE)(pszSrc_End - pszSrc_Start) < KTgMAX_U32);

        tgSrc.m_unData.m_pszSrc = pszSrc_Start;
        tgSrc.m_uiBuffer = tgSZ_Length( pszSrc_Start );
        tgSrc.m_uiReserve = KTgMAX_SIZE;

        tgCM_UTS_ST_SF_Replace( psDest, uiStart, uiEnd, &tgSrc, 0, (TgSIZE)(pszSrc_End - pszSrc_Start) );
    }
    else
    {
        tgCM_UTS_SF_Erase( psDest, uiStart, uiEnd - uiStart );
    };
}


/* ---- tgCM_UTS_ST_ST_Replace ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_ST_Replace( PC_STg2_UTS_ST psDest, C_TgSIZE uiStart, C_TgSIZE uiEnd, CPC_STg2_UTS_ST psSrc )
{
    tgCM_UTS_ST_SF_Replace( psDest, uiStart, uiEnd, psSrc, 0, KTgMAX_SIZE );
}


/* ---- tgCM_UTS_ST_SO_Replace ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_SO_Replace( PC_STg2_UTS_ST psDest, C_TgSIZE uiStart, C_TgSIZE uiEnd, CPC_STg2_UTS_ST psSrc, C_TgSIZE uiOffset )
{
    tgCM_UTS_ST_SF_Replace( psDest, uiStart, uiEnd, psSrc, uiOffset, KTgMAX_SIZE );
}


/* ---- tgCM_UTS_ST_Clear ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Clear( PC_STg2_UTS_ST psDest )
{
    if (psDest->m_uiReserve > KTgSTRING_STATIC_BUFFER_SIZE)
    {
        TgFREE_POOL( psDest->m_unData.m_pszDest );
        psDest->m_uiReserve = KTgSTRING_STATIC_BUFFER_SIZE;
    };

    psDest->m_uiBuffer = 0;
    psDest->m_unData.m_aBuffer[0] = TgT('\0');
}


/* ---- tgCM_UTS_ST_Format ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Format( PC_STg2_UTS_ST psDest, CPC_TgCHAR pText, ... )
{
    va_list                             arg_list;

    va_start( arg_list, pText );

    tgCM_UTS_ST_Clear( psDest );

    if (TgEXPECT_TRUE( nullptr != pText ))
    {
        TgSINT32                            iLength = tgSZ_LengthVF( pText, arg_list );

        tgCM_UTS_ST_Resize( psDest, (TgSIZE)iLength, TgT('\0') );

        tgSZ_PrintVF(
            KTgSTRING_STATIC_BUFFER_SIZE < psDest->m_uiReserve ? psDest->m_unData.m_pszDest : psDest->m_unData.m_aBuffer,
            psDest->m_uiReserve, pText, arg_list );

        psDest->m_uiBuffer = (TgSIZE)iLength;
    };

    va_end( arg_list );
}


/* ---- tgCM_UTS_ST_Query_String ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE CP_TgCHAR tgCM_UTS_ST_Query_String( CPC_STg2_UTS_ST psDest )
{
    return (KTgSTRING_STATIC_BUFFER_SIZE < psDest->m_uiReserve ? psDest->m_unData.m_pszDest : psDest->m_unData.m_aBuffer);
}


/* ---- tgCM_UTS_ST_To_Upper -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_To_Upper( PC_STg2_UTS_ST psDest )
{
    tgSZ_To_Upper(
        KTgSTRING_STATIC_BUFFER_SIZE < psDest->m_uiReserve ? psDest->m_unData.m_pszDest : psDest->m_unData.m_aBuffer,
        KTgSTRING_STATIC_BUFFER_SIZE < psDest->m_uiReserve ? psDest->m_uiBuffer : KTgSTRING_STATIC_BUFFER_SIZE - 1
        );
}


/* ---- tgCM_UTS_ST_To_Lower -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_To_Lower( PC_STg2_UTS_ST psDest )
{
    tgSZ_To_Lower(
        KTgSTRING_STATIC_BUFFER_SIZE < psDest->m_uiReserve ? psDest->m_unData.m_pszDest : psDest->m_unData.m_aBuffer,
        KTgSTRING_STATIC_BUFFER_SIZE < psDest->m_uiReserve ? psDest->m_uiBuffer : KTgSTRING_STATIC_BUFFER_SIZE - 1
        );
}


/* ---- tgCM_UTS_ST_Is_Empty -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_UTS_ST_Is_Empty( CPC_STg2_UTS_ST psDest )
{
    return (0 == psDest->m_uiBuffer);
}


/* ---- tgCM_UTS_ST_Capacity -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_ST_Capacity( CPC_STg2_UTS_ST psDest )
{
    return (psDest->m_uiReserve - 1);
}


/* ---- tgCM_UTS_ST_Size ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_ST_Size( CPC_STg2_UTS_ST psDest )
{
    return (psDest->m_uiBuffer);
}


/* ---- tgCM_UTS_ST_Max_size -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_ST_Max_size( CPC_STg2_UTS_ST UNUSED_PARAM psDest )
{
    return (KTgMAX_U32 - 1);
}


/* ---- tgCM_UTS_ST_Length ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_ST_Length( CPC_STg2_UTS_ST psDest )
{
    return (psDest->m_uiBuffer);
}


/* ---- tgCM_UTS_ST_Swap ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Swap( PC_STg2_UTS_ST psLeft, PC_STg2_UTS_ST psRight )
{
    STg2_UTS_ST                         tgTmp;

    memcpy( &tgTmp, psLeft, sizeof( STg2_UTS_ST ) );
    memcpy( psLeft, psRight, sizeof( STg2_UTS_ST ) );
    memcpy( psRight, &tgTmp, sizeof( STg2_UTS_ST ) );
}

/* ---- tgCM_UTS_ST_Reserve --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Reserve( PC_STg2_UTS_ST psDest, C_TgSIZE uiNew_Size )
{
    if (TgEXPECT_TRUE( uiNew_Size + 1 > psDest->m_uiReserve ))
    {
        tgCM_UTS_ST_Resize( psDest, uiNew_Size, TgT('\0') );
    };
}


/* ---- tgCM_UTS_ST_Is_Inside ------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Test if pszRight points inside string */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_UTS_ST_Is_Inside( CPC_STg2_UTS_ST psDest, CPC_TgCHAR pszRight )
{
    return (tgCM_UTS_ST_Query_String( psDest ) <= pszRight && pszRight <= tgCM_UTS_ST_Query_String( psDest ) + psDest->m_uiBuffer);
}


/* ---- tgCM_UTS_ST_ST_Compare ------------------------------------------------------------------------------------------------------------------------------------------ */
/*  Compare [0, psDest->m_uiBuffer) with szRight  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 tgCM_UTS_ST_ST_Compare( CPC_STg2_UTS_ST psLeft, CPC_STg2_UTS_ST psRight )
{
    return (tgCM_UTS_SF_SF_Compare( psLeft, 0, psLeft->m_uiBuffer, psRight, 0, psRight->m_uiBuffer ));
}


/* ---- tgCM_UTS_SF_ST_Compare ------------------------------------------------------------------------------------------------------------------------------------------ */
/*  Compare [uiOffset, uiOffset + uiLength) with szRight  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 tgCM_UTS_SF_ST_Compare( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, C_TgSIZE uiLLength, CPC_STg2_UTS_ST psRight )
{
    return (tgCM_UTS_SF_SF_Compare( psLeft, uiLOffset, uiLLength, psRight, 0, psRight->m_uiBuffer ));
}


/* ---- tgCM_UTS_SF_SF_Compare ------------------------------------------------------------------------------------------------------------------------------------------ */
/*  Compare [uiOffset, uiOffset + uiLength) with szRight [uiROffset, uiROffset + uiCount)  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 tgCM_UTS_SF_SF_Compare( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, C_TgSIZE uiLLength, CPC_STg2_UTS_ST psRight, C_TgSIZE uiROffset, C_TgSIZE uiRLength )
{
    C_TgSIZE                            uiLSize = tgCM_MIN_UXX( uiLLength, psLeft->m_uiBuffer - uiLOffset );
    C_TgSIZE                            uiRSize = tgCM_MIN_UXX( uiRLength, psRight->m_uiBuffer - uiROffset );

    if (TgEXPECT_FALSE( !(uiLSize > 0 && uiLOffset < psLeft->m_uiBuffer && uiRSize > 0 && uiROffset < psRight->m_uiBuffer) ))
    {
        TgERROR_MSGF( 0, TgT("%-16.16s(%-32.32s): Invalid Parameters.\n"), TgT("Common"), TgT("CM_UTS_SF_SF_Compare") );
        return (-1);
    }
    else
    {
        CPC_TgCHAR                          pszLeft = tgCM_UTS_ST_Query_String( psLeft ) + uiLOffset;
        CPC_TgCHAR                          pszRight = tgCM_UTS_ST_Query_String( psRight ) + uiROffset;
        TgSINT32                            iRet;

        if (0 != (iRet = tgSZ_CompareN( pszLeft, pszRight, tgCM_MIN_UXX( uiLSize, uiRSize ) )))
        {
            return (iRet);
        }
        else
        {
            return (tgCM_SGN_S32( (TgSINT32)(uiLSize - uiRSize) ));
        };
    };
}


/* ---- tgCM_UTS_ST_SZ_Compare ------------------------------------------------------------------------------------------------------------------------------------------ */
/*  Compare [0, psDest->m_uiBuffer) with [pszRight, <null>)  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 tgCM_UTS_ST_SZ_Compare( CPC_STg2_UTS_ST psLeft, CPC_TgCHAR pszRight )
{
    STg2_UTS_ST                       tgSrc;

    tgSrc.m_unData.m_pszSrc = pszRight;
    tgSrc.m_uiBuffer = tgSZ_Length( pszRight );
    tgSrc.m_uiReserve = KTgMAX_SIZE;

    return (tgCM_UTS_SF_SF_Compare( psLeft, 0, psLeft->m_uiBuffer, &tgSrc, 0, tgSrc.m_uiBuffer ));
}


/* ---- tgCM_UTS_SF_SZ_Compare ------------------------------------------------------------------------------------------------------------------------------------------ */
/*  Compare [uiOffset, uiOffset + uiLength) with [pszRight, <null>)  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 tgCM_UTS_SF_SZ_Compare( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiOffset, C_TgSIZE uiLength, CPC_TgCHAR pszRight )
{
    STg2_UTS_ST                       tgSrc;

    tgSrc.m_unData.m_pszSrc = pszRight;
    tgSrc.m_uiBuffer = tgSZ_Length( pszRight );
    tgSrc.m_uiReserve = KTgMAX_SIZE;

    return (tgCM_UTS_SF_SF_Compare( psLeft, uiOffset, uiLength, &tgSrc, 0, tgSrc.m_uiBuffer ));
}


/* ---- tgCM_UTS_SF_SN_Compare ------------------------------------------------------------------------------------------------------------------------------------------ */
/*  Compare [uiOffset, uiOffset + uiLength) with [pszRight, pszRight + uiCount)  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 tgCM_UTS_SF_SN_Compare( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiOffset, C_TgSIZE uiLength, CPC_TgCHAR pszRight, C_TgSIZE uiRLength )
{
    STg2_UTS_ST                       tgSrc;

    tgSrc.m_unData.m_pszSrc = pszRight;
    tgSrc.m_uiBuffer = tgSZ_Length( pszRight );
    tgSrc.m_uiReserve = KTgMAX_SIZE;

    return (tgCM_UTS_SF_SF_Compare( psLeft, uiOffset, uiLength, &tgSrc, 0, uiRLength ));
}


/* ---- tgCM_UTS_SO_ST_Find_String -------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for szRight beginning at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_ST_Find_String( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_STg2_UTS_ST psRight )
{
    return (tgCM_UTS_SO_SF_Find_String( psLeft, uiLOffset, psRight, 0, KTgMAX_SIZE ));
}


/* ---- tgCM_UTS_SO_SZ_Find_String -------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for [pszRight, <null>) beginning at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SZ_Find_String( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight )
{
    STg2_UTS_ST                       tgSrc;

    tgSrc.m_unData.m_pszSrc = pszRight;
    tgSrc.m_uiBuffer = tgSZ_Length( pszRight );
    tgSrc.m_uiReserve = KTgMAX_SIZE;

    return (tgCM_UTS_SO_SF_Find_String( psLeft, uiLOffset, &tgSrc, 0, KTgMAX_SIZE ));
}


/* ---- tgCM_UTS_SO_SN_Find_String -------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for [pszRight, pszRight + uiRLength) beginning at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SN_Find_String( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight, C_TgSIZE uiRLength )
{
    STg2_UTS_ST                       tgSrc;

    tgSrc.m_unData.m_pszSrc = pszRight;
    tgSrc.m_uiBuffer = tgSZ_Length( pszRight );
    tgSrc.m_uiReserve = KTgMAX_SIZE;

    return (tgCM_UTS_SO_SF_Find_String( psLeft, uiLOffset, &tgSrc, 0, uiRLength ));
}


/* ---- tgCM_UTS_SO_ST_Find_Set ----------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for one of szRight at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_ST_Find_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_STg2_UTS_ST psRight )
{
    return (tgCM_UTS_SO_SN_Find_Set( psLeft, uiLOffset, tgCM_UTS_ST_Query_String( psRight ), tgCM_UTS_ST_Size( psRight ) ));
}


/* ---- tgCM_UTS_SO_SZ_Find_Set ----------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for one of [pszRight, <null>) at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SZ_Find_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight )
{
    return (tgCM_UTS_SO_SN_Find_Set( psLeft, uiLOffset, pszRight, tgSZ_Length( pszRight ) ));
}


/* ---- tgCM_UTS_SO_SN_Find_Set ----------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for one of [pszRight, pszRight + uiCount) at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SN_Find_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight, C_TgSIZE uiCount )
{
    if (TgEXPECT_FALSE( !((0 != uiCount) && (uiLOffset < psLeft->m_uiBuffer)) ))
    {
        return (KTgMAX_SIZE);
    }
    else
    {
        CPC_TgCHAR                          pszLeft = tgCM_UTS_ST_Query_String( psLeft );
        CPC_TgCHAR                          pszLLast = pszLeft + psLeft->m_uiBuffer;
        CPC_TgCHAR                          pszRLast = pszRight + uiCount;
        CP_TgCHAR                           pszCurrent, pszSet;

        for (pszCurrent = pszLeft + uiLOffset; pszCurrent < pszLLast; ++pszCurrent)
        {
            for (pszSet = pszRight; pszSet < pszRLast; ++pszSet)
            {
                if (*pszCurrent == *pszSet)
                {
                    return ((TgSIZE)(pszCurrent - pszLeft)); /* Found a match */
                };
            };
        };

        return (KTgMAX_SIZE); /* No match */
    };
}


/* ---- tgCM_UTS_SO_Find_Char ------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for uiChar at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_Find_Char( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, C_TgCHAR uiChar )
{
    if (TgEXPECT_FALSE( !(uiLOffset < psLeft->m_uiBuffer) ))
    {
        return (KTgMAX_SIZE);
    }
    else
    {
        CPC_TgCHAR                          pszLeft = tgCM_UTS_ST_Query_String( psLeft );
        CPC_TgCHAR                          pszLLast = pszLeft + psLeft->m_uiBuffer;
        CP_TgCHAR                           pszCurrent;

        for (pszCurrent = pszLeft + uiLOffset; pszCurrent < pszLLast; ++pszCurrent)
        {
            if (*pszCurrent == uiChar)
            {
                return ((TgSIZE)(pszCurrent - pszLeft)); /* Found a match */
            };
        };

        return (KTgMAX_SIZE); /* No match */
    };
}


/* ---- tgCM_UTS_SO_ST_Find_Not_Set ------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for none of szRight at or after uiOffset  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_ST_Find_Not_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_STg2_UTS_ST psRight )
{
    return (tgCM_UTS_SO_SN_Find_Not_Set( psLeft, uiLOffset, tgCM_UTS_ST_Query_String( psRight ), tgCM_UTS_ST_Size( psRight ) ));
}


/* ---- tgCM_UTS_SO_SZ_Find_Not_Set ------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for one of [pszRight, <null>) at or after uiOffset  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SZ_Find_Not_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight )
{
    return (tgCM_UTS_SO_SN_Find_Not_Set( psLeft, uiLOffset, pszRight, tgSZ_Length( pszRight ) ));
}


/* ---- tgCM_UTS_SO_SN_Find_Not_Set ------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for none of [pszRight, pszRight + uiCount) at or after uiOffset  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SN_Find_Not_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight, C_TgSIZE uiCount )
{
    if (TgEXPECT_FALSE( !((0 != uiCount) && (uiLOffset < psLeft->m_uiBuffer)) ))
    {
        return (KTgMAX_SIZE);
    }
    else
    {
        CPC_TgCHAR                          pszLeft = tgCM_UTS_ST_Query_String( psLeft );
        CPC_TgCHAR                          pszLLast = pszLeft + psLeft->m_uiBuffer;
        CPC_TgCHAR                          pszRLast = pszRight + uiCount;
        CP_TgCHAR                           pszCurrent, pszSet;

        for (pszCurrent = pszLeft + uiLOffset; pszCurrent < pszLLast; ++pszCurrent)
        {
            for (pszSet = pszRight; *pszCurrent != *pszSet && pszSet < pszRLast; ++pszSet);

            if (pszSet == pszRLast)
            {
                return ((TgSIZE)(pszCurrent - pszLeft)); /* Found a match */
            }
        };

        return (KTgMAX_SIZE); /* No match */
    };
}


/* ---- tgCM_UTS_SO_Find_Not_Char --------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for non uiChar at or after uiOffset  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_Find_Not_Char( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, C_TgCHAR uiChar )
{
    if (TgEXPECT_FALSE( !(uiLOffset < psLeft->m_uiBuffer) ))
    {
        return (KTgMAX_SIZE);
    }
    else
    {
        CPC_TgCHAR                          pszLeft = tgCM_UTS_ST_Query_String( psLeft );
        CPC_TgCHAR                          pszLLast = pszLeft + psLeft->m_uiBuffer;
        CP_TgCHAR                           pszCurrent;

        for (pszCurrent = pszLeft + uiLOffset; pszCurrent < pszLLast; ++pszCurrent)
        {
            if (*pszCurrent != uiChar)
            {
                return ((TgSIZE)(pszCurrent - pszLeft)); /* Found a match */
            };
        };

        return (KTgMAX_SIZE); /* No match */
    };
}


/* ---- tgCM_UTS_SO_ST_RFind_String ------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for szRight beginning at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_ST_RFind_String( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_STg2_UTS_ST psRight )
{
    return (tgCM_UTS_SO_SF_RFind_String( psLeft, uiLOffset, psRight, 0, KTgMAX_SIZE ));
}


/* ---- tgCM_UTS_SO_SZ_RFind_String ------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for [pszRight, <null>) beginning at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SZ_RFind_String( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight )
{
    STg2_UTS_ST                       tgSrc;

    tgSrc.m_unData.m_pszSrc = pszRight;
    tgSrc.m_uiBuffer = tgSZ_Length( pszRight );
    tgSrc.m_uiReserve = KTgMAX_SIZE;

    return (tgCM_UTS_SO_SF_RFind_String( psLeft, uiLOffset, &tgSrc, 0, KTgMAX_SIZE ));
}


/* ---- tgCM_UTS_SO_SN_RFind_String ------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for [pszRight, pszRight + uiCount) beginning at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SN_RFind_String( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight, C_TgSIZE uiRLength )
{
    STg2_UTS_ST                       tgSrc;

    tgSrc.m_unData.m_pszSrc = pszRight;
    tgSrc.m_uiBuffer = tgSZ_Length( pszRight );
    tgSrc.m_uiReserve = KTgMAX_SIZE;

    return (tgCM_UTS_SO_SF_RFind_String( psLeft, uiLOffset, &tgSrc, 0, uiRLength ));
}


/* ---- tgCM_UTS_SO_ST_RFind_Set ---------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for one of szRight at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_ST_RFind_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_STg2_UTS_ST psRight )
{
    return (tgCM_UTS_SO_SN_RFind_Set( psLeft, uiLOffset, tgCM_UTS_ST_Query_String( psRight ), tgCM_UTS_ST_Size( psRight ) ));
}


/* ---- tgCM_UTS_SO_SZ_RFind_Set ---------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for one of [pszRight, <null>) at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SZ_RFind_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight )
{
    return (tgCM_UTS_SO_SN_RFind_Set( psLeft, uiLOffset, pszRight, tgSZ_Length( pszRight ) ));
}


/* ---- tgCM_UTS_SO_SN_RFind_Set ---------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for one of [pszRight, pszRight + uiCount) at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SN_RFind_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight, C_TgSIZE uiCount )
{
    if (TgEXPECT_FALSE( !((0 != uiCount) && (uiLOffset < psLeft->m_uiBuffer)) ))
    {
        return (KTgMAX_SIZE);
    }
    else
    {
        CPC_TgCHAR                          pszLeft = tgCM_UTS_ST_Query_String( psLeft );
        CPC_TgCHAR                          pszRLast = pszRight + uiCount;
        CP_TgCHAR                           pszCurrent, pszSet;

        for (pszCurrent = pszLeft + psLeft->m_uiBuffer - uiLOffset - 1; pszCurrent >= pszLeft; --pszCurrent)
        {
            for (pszSet = pszRight; pszSet < pszRLast; ++pszSet)
            {
                if (*pszCurrent == *pszSet)
                {
                    return ((TgSIZE)(pszCurrent - pszLeft)); /* Found a match */
                };
            };
        };

        return (KTgMAX_SIZE); /* No match */
    };
}


/* ---- tgCM_UTS_SO_RFind_Char ------------------------------------------------------------------------------------------------------------------------------------------ */
/*  Look for uiChar at or after uiOffset */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_RFind_Char( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, C_TgCHAR uiChar )
{
    if (TgEXPECT_FALSE( !(uiLOffset < psLeft->m_uiBuffer) ))
    {
        return (KTgMAX_SIZE);
    }
    else
    {
        CPC_TgCHAR                          pszLeft = tgCM_UTS_ST_Query_String( psLeft );
        CP_TgCHAR                           pszCurrent;

        for (pszCurrent = pszLeft + psLeft->m_uiBuffer - uiLOffset - 1; pszCurrent >= pszLeft; --pszCurrent)
        {
            if (*pszCurrent == uiChar)
            {
                return ((TgSIZE)(pszCurrent - pszLeft)); /* Found a match */
            };
        };

        return (KTgMAX_SIZE); /* No match */
    };
}


/* ---- tgCM_UTS_SO_ST_RFind_Not_Set ------------------------------------------------------------------------------------------------------------------------------------ */
/*  Look for none of szRight at or after uiOffset  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_ST_RFind_Not_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_STg2_UTS_ST psRight )
{
    return (tgCM_UTS_SO_SN_RFind_Not_Set( psLeft, uiLOffset, tgCM_UTS_ST_Query_String( psRight ), tgCM_UTS_ST_Size( psRight ) ));
}


/* ---- tgCM_UTS_SO_SZ_RFind_Not_Set ------------------------------------------------------------------------------------------------------------------------------------ */
/*  Look for one of [pszRight, <null>) at or after uiOffset  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SZ_RFind_Not_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight )
{
    return (tgCM_UTS_SO_SN_RFind_Not_Set( psLeft, uiLOffset, pszRight, tgSZ_Length( pszRight ) ));
}


/* ---- tgCM_UTS_SO_SN_RFind_Not_Set ------------------------------------------------------------------------------------------------------------------------------------ */
/*  Look for none of [pszRight, pszRight + uiCount) at or after uiOffset  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_SN_RFind_Not_Set( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, CPC_TgCHAR pszRight, C_TgSIZE uiCount )
{
    if (TgEXPECT_FALSE( !((0 != uiCount) && (uiLOffset < psLeft->m_uiBuffer)) ))
    {
        return (KTgMAX_SIZE);
    }
    else
    {
        CPC_TgCHAR                          pszLeft = tgCM_UTS_ST_Query_String( psLeft );
        CPC_TgCHAR                          pszRLast = pszRight + uiCount;
        CP_TgCHAR                           pszCurrent, pszSet;

        for (pszCurrent = pszLeft + psLeft->m_uiBuffer - uiLOffset - 1; pszCurrent >= pszLeft; --pszCurrent)
        {
            for (pszSet = pszRight; *pszCurrent != *pszSet && pszSet < pszRLast; ++pszSet);

            if (pszSet == pszRLast)
            {
                return ((TgSIZE)(pszCurrent - pszLeft)); /* Found a match */
            }
        };

        return (KTgMAX_SIZE); /* No match */
    };
}


/* ---- tgCM_UTS_SO_RFind_Not_Char -------------------------------------------------------------------------------------------------------------------------------------- */
/*  Look for non uiChar at or after uiOffset  */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSIZE tgCM_UTS_SO_RFind_Not_Char( CPC_STg2_UTS_ST psLeft, C_TgSIZE uiLOffset, C_TgCHAR uiChar )
{
    if (TgEXPECT_FALSE( !(uiLOffset < psLeft->m_uiBuffer) ))
    {
        return (KTgMAX_SIZE);
    }
    else
    {
        CPC_TgCHAR                          pszLeft = tgCM_UTS_ST_Query_String( psLeft );
        CP_TgCHAR                           pszCurrent;

        for (pszCurrent = pszLeft + psLeft->m_uiBuffer - uiLOffset - 1; pszCurrent >= pszLeft; --pszCurrent)
        {
            if (*pszCurrent != uiChar)
            {
                return ((TgSIZE)(pszCurrent - pszLeft)); /* Found a match */
            };
        };

        return (KTgMAX_SIZE); /* No match */
    };
}


/* ---- tgCM_UTS_ST_Trim_Start_Char ------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Trim_Start_Char( PC_STg2_UTS_ST psDest, C_TgCHAR uiChar )
{
    C_TgSIZE                            uiIdx = tgCM_UTS_SO_Find_Not_Char( psDest, 0, uiChar );

    if (uiIdx != KTgMAX_SIZE)
    {
        tgCM_UTS_SF_Erase( psDest, 0, uiIdx );
    }
    else
    {
        tgCM_UTS_ST_Clear( psDest );
    };
}


/* ---- tgCM_UTS_ST_Trim_Start_Set -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Trim_Start_Set( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszRight, C_TgSIZE uiCount )
{
    C_TgSIZE                            uiIdx = tgCM_UTS_SO_SN_Find_Not_Set( psDest, 0, pszRight, uiCount );

    if (uiIdx != KTgMAX_SIZE)
    {
        tgCM_UTS_SF_Erase( psDest, 0, uiIdx );
    }
    else
    {
        tgCM_UTS_ST_Clear( psDest );
    };
}


/* ---- tgCM_UTS_ST_Trim_End_Char --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Trim_End_Char( PC_STg2_UTS_ST psDest, C_TgCHAR uiChar )
{
    C_TgSIZE                            uiIdx = tgCM_UTS_SO_RFind_Not_Char( psDest, 0, uiChar );

    if (uiIdx != KTgMAX_SIZE)
    {
        tgCM_UTS_SF_Erase( psDest, uiIdx + 1, psDest->m_uiBuffer - uiIdx );
    }
    else
    {
        tgCM_UTS_ST_Clear( psDest );
    };
}


/* ---- tgCM_UTS_ST_Trim_End_Set ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_ST_Trim_End_Set( PC_STg2_UTS_ST psDest, CPC_TgCHAR pszRight, C_TgSIZE uiCount )
{
    C_TgSIZE                            uiIdx = tgCM_UTS_SO_SN_RFind_Not_Set( psDest, 0, pszRight, uiCount );

    if (uiIdx != KTgMAX_SIZE)
    {
        tgCM_UTS_SF_Erase( psDest, uiIdx + 1, psDest->m_uiBuffer - uiIdx );
    }
    else
    {
        tgCM_UTS_ST_Clear( psDest );
    };
}


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