Changeset 1276 for cpp


Ignore:
Timestamp:
09/09/23 15:20:04 (16 months ago)
Author:
Maciej Komosinski
Message:

Added ends_with() for std::string

Location:
cpp/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/util-string.cpp

    r1130 r1276  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    108108}
    109109
     110bool ends_with(std::string_view str, std::string_view suffix)
     111{
     112        return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
     113}
     114
     115
    110116char* strmove(char *a, char *b) //strcpy that works well for overlapping strings ("Source and destination overlap")
    111117{
  • cpp/common/util-string.h

    r1125 r1276  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1414bool str_starts_with(const char *str, const char *prefix);
    1515inline bool starts_with(const string& str, const char *prefix) { return str_starts_with(str.c_str(),prefix); } //std::string.starts_with(...) since c++20
     16bool ends_with(std::string_view str, std::string_view suffix);
    1617
    1718string ssprintf(const char* format, ...);
Note: See TracChangeset for help on using the changeset viewer.