VirtualBox

Changeset 95814 in vbox


Ignore:
Timestamp:
Jul 25, 2022 1:25:01 PM (2 years ago)
Author:
vboxsync
Message:

IPRT/string: Added simple strstr, strrchr and strcspn implementations for IPRT_NO_CRT mode. bugref:10261

Location:
trunk/src/VBox/Runtime/common/string
Files:
2 added
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/strcspn.cpp

    r95811 r95814  
    11/* $Id$ */
    22/** @file
    3  * IPRT - strpbrk().
     3 * IPRT - CRT Strings, strcspn().
    44 */
    55
     
    3333
    3434/**
    35  * Find the first occurrence of a character in pszChars in pszStr.
    36  *
    37  * @returns
     35 * strpbrk with a offset return instead of a pointer.
    3836 */
    39 #ifdef IPRT_NO_CRT
    40 char *strpbrk(const char *pszStr, const char *pszBreakChars)
    41 #elif defined(_MSC_VER)
    42 # if _MSC_VER >= 1400
    43 _CRTIMP __checkReturn _CONST_RETURN char *  __cdecl strpbrk(__in_z const char *pszStr, __in_z const char *pszBreakChars)
    44 # else
    45 _CRTIMP char * __cdecl strpbrk(const char *pszStr, const char *pszBreakChars)
    46 # endif
    47 #elif defined(__WATCOMC__)
    48 _WCRTLINK char *std::strpbrk(const char *pszStr, const char *pszBreakChars)
    49 #else
    50 char *strpbrk(const char *pszStr, const char *pszBreakChars)
    51 # if defined(__THROW) && !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2)
    52     __THROW
    53 # endif
    54 #endif
     37size_t strcspn(const char *pszString, const char *pszBreakChars)
    5538{
    56     int chCur;
    57     while ((chCur = *pszStr++) != '\0')
     39    const char * const pszStringStart = pszString;
     40    int                chCur;
     41    while ((chCur = *pszString++) != '\0')
    5842    {
    59         int chBreak;
    60         const char *psz = pszBreakChars;
     43        int            chBreak;
     44        const char    *psz = pszBreakChars;
    6145        while ((chBreak = *psz++) != '\0')
    6246            if (chBreak == chCur)
    63                 return (char *)(pszStr - 1);
     47                return (size_t)(pszString - pszStringStart + 1);
    6448
    6549    }
    66     return NULL;
     50    return (size_t)(pszString - pszStringStart);
    6751}
    6852
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette