Changeset 2947


Ignore:
Timestamp:
Sep 18, 2013, 9:16:40 PM (6 years ago)
Author:
touky
Message:

String : Added ::replace(char, char, bool), ::ToLower(), ::ToUpper()
Added utils.h : GetRandom(Array<T>) : gets a random element in a template list with weight logic.

T FindValue(char*) : Find the value of a safe enum from the given name (when GetName is implemented)
swap(T&, T&) is now in here too.

Location:
trunk/src
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r2843 r2947  
    1212    tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h \
    1313    world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \
    14     profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.h numeric.h \
     14    profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.h numeric.h utils.h \
    1515    worldentity.cpp worldentity.h gradient.cpp gradient.h gradient.lolfx \
    1616    platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \
  • trunk/src/core.h

    r2841 r2947  
    118118#include <lol/debug/all.h>
    119119
     120#include "utils.h"
    120121#include "numeric.h"
    121122
  • trunk/src/lol/base/string.h

    r2917 r2947  
    146146        char const *tmp = strrchr(C(), token);
    147147        return tmp ? (int)(intptr_t)(tmp - C()) : -1;
     148    }
     149
     150    int Replace(const char old_token, const char new_token, bool all_occurence=false)
     151    {
     152        using namespace std;
     153
     154        int res = 0;
     155        char *tmp = NULL;
     156        while ((tmp = strrchr(C(), old_token)))
     157        {
     158            *tmp = new_token;
     159            res++;
     160            if (!all_occurence)
     161                break;
     162        }
     163        return res;
     164    }
     165
     166    inline String& ToLower()
     167    {
     168        char* p = C();
     169        for (int i = 0; i < Count(); ++i)
     170            if ('A' <= p[i] && p[i] <= 'Z')
     171                p[i] += 'a' - 'A';
     172        return *this;
     173    }
     174
     175    inline String& ToUpper()
     176    {
     177        char* p = C();
     178        for (int i = 0; i < Count(); ++i)
     179            if ('a' <= p[i] && p[i] <= 'z')
     180                p[i] += 'A' - 'a';
     181        return *this;
    148182    }
    149183
  • trunk/src/lolcore.vcxproj

    r2879 r2947  
    275275    <ClInclude Include="tiler.h" />
    276276    <ClInclude Include="tileset.h" />
     277    <ClInclude Include="utils.h" />
    277278    <ClInclude Include="video.h" />
    278279    <ClInclude Include="world.h" />
  • trunk/src/lolcore.vcxproj.filters

    r2842 r2947  
    609609      <Filter>input</Filter>
    610610    </ClInclude>
     611    <ClInclude Include="utils.h">
     612      <Filter>...</Filter>
     613    </ClInclude>
    611614  </ItemGroup>
    612615  <ItemGroup>
  • trunk/src/numeric.h

    r2932 r2947  
    4444}
    4545
    46 template< class T > inline void Swap( T& A, T& B )
    47 {
    48     const T Temp = A;
    49     A = B;
    50     B = Temp;
    51 }
    52 
    5346//SmoothClamp clamps x in [a - sd, b + sd] and returns a value in [a, b] that is smoothed at the borders.
    5447static inline float SmoothClamp(float &x, float a, float b, float sd)
Note: See TracChangeset for help on using the changeset viewer.