String library.

Dependents:   CheckSum RN41 RealTimeClock TVZ_MU_Seminar ... more

Files at this revision

API Documentation at this revision

Comitter:
AkinoriHashimoto
Date:
Mon Jun 29 01:51:12 2015 +0000
Parent:
0:058192932ad2
Child:
2:14f3ff21096e
Commit message:
my string library.

Changed in this revision

StrLib.cpp Show annotated file Show diff for this revision Revisions of this file
StrLib.h Show annotated file Show diff for this revision Revisions of this file
--- a/StrLib.cpp	Thu Jun 11 01:50:08 2015 +0000
+++ b/StrLib.cpp	Mon Jun 29 01:51:12 2015 +0000
@@ -56,4 +56,26 @@
     if(id == string::npos)
         return false;
     return id == idx;
+}
+
+string toAlpanumeric(string str, bool toLarge)
+{
+    string ans= "";
+    bool num, small, large;
+    for (int i= 0; i < str.size(); i++) {
+        num= small= large= false;
+        if('0' <= str[i] && str[i] <= '9')
+            num= true;
+        else if('A' <= str[i] && str[i] <= 'Z')
+            large= true;
+        else if('a' <= str[i] && str[i] <= 'z')
+            small= true;
+        
+        if(toLarge && small)
+            str[i] -= 0x20;  // small -> large
+        if(num || large || small)
+            ans += str[i];
+    }
+    
+    return ans;
 }
\ No newline at end of file
--- a/StrLib.h	Thu Jun 11 01:50:08 2015 +0000
+++ b/StrLib.h	Mon Jun 29 01:51:12 2015 +0000
@@ -2,22 +2,25 @@
 
 #include "mbed.h"
 #include <string>
-// class化しないとダメなんだけど。。。
+
 
-/** String -> long
+/** String(Ascii) -> long(int)
  * @param   string target(str), int Base(8Oct, 10Dec, 16Hex)
  * @return  long int
 */
-long   A2I(string, int);           // Ascii → Intへ変換する関数。
+long   A2I(string, int);
 
 /** int -> string
  * @param   int target(num), int Base(8Oct, 10Dec, 16Hex), int Number of digit
  * @return  string str
 */
-string I2A(int num, int base= 10, int digitNum= 0);   // 標準引数
+string I2A(int num, int base= 10, int digitNum= 0);
 
 /** string Compare
  * @param   string target, string cmp, int index in target
  * @return  bool
 */
 bool strCompare(string trg, string cmp, int idx);   // trg内にcmpが存在する位置がidxか判定。
+
+
+string toAlpanumeric(string str, bool large=false);
\ No newline at end of file