1 /**
2  * Skadi.d Web Framework
3  *
4  * component/string - PHP alike functions.
5  *
6  * Authors: Faianca
7  * Copyright: Copyright (c) 2015 Faianca
8  * License: MIT License, see LICENSE
9  */
10 module skadi.components..string.transform;
11 
12 string ctToLower(string str) pure
13 {
14     char[] mstr = str.dup;
15     foreach(i, c; mstr)
16     {
17         if (c >= 'A' && c <= 'Z')
18         {
19             mstr[i] += 32;
20         }
21     }
22     return mstr.idup;
23 }
24 
25 /**
26  * Quick and dirty hack for making the first character of a string lower case
27  *
28  * Note: The first character must be upper case
29  *
30  * Params:
31  *  str = string to operate on
32  * Returns:
33  *  Same string but with the first character using lowercase
34  */
35 string lcfirst(string str)
36 {
37     assert(str[0] >= 'A' && str[0] <= 'Z');
38     return cast(char)(str[0]+32) ~ str[1..$];
39 }
40 
41 /**
42  * Quick and dirty hack for making the first character of a string upper case
43  *
44  * Note: The first character must be lower case
45  *
46  * Params:
47  *  str = string to operate on
48  * Returns:
49  *  Same string but with the first character using uppercase
50  */
51 string ucfirst(string str)
52 {
53     assert(str[0] >= 'a' && str[0] <= 'z');
54     return cast(char)(str[0]-32) ~ str[1..$];
55 }