Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: matchLine.cpp
- Revision:
- 4:acfd6fbf9f9e
- Child:
- 5:6105553963bb
diff -r 5720d24f4a4a -r acfd6fbf9f9e matchLine.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/matchLine.cpp Sun Jul 05 08:09:02 2015 +0000 @@ -0,0 +1,51 @@ +#include <mbed.h> +#include <stdio.h> +#include <string.h> +#include <vector> + +#include <SDFileSystem.h> +#include "matchLine.h" + +SDFileSystem sdCard(PTE3, PTE1, PTE2, PTE4, "sd"); + +#define ERR(x, ...) std::printf("[DigitalClock : ERR]"x"\r\n", ##__VA_ARGS__); + +matchLine::matchLine() {} ; +matchLine:: ~matchLine () { }; + +static void removeCRLF(char *str) +{ + for(int i = strlen(str)-1; i>0 ; i--) { + if((str[strlen(str)-1] == '\n') || (str[strlen(str)-1] == '\r')) + str[strlen(str)-1] = '\0' ; + else break ; + } +} + +bool matchLine::getList(string filename) +{ + int cnt = 0 ; + char line[100] ; + FILE *fp ; + fp = fopen(filename.c_str(), "r"); + if (fp == NULL) { + ERR("Cannot open \"%s\"\n",filename.c_str()) ; + return false ; + } + while (fgets(line, sizeof(line), fp)) { + removeCRLF(line) ; + list.push_back(line) ; + } + return true ; +} + +bool matchLine::find(string line) +{ + int pos ; + string name ; + for(int i=0; i<list.size(); i++) { + pos = line.find(list[i]) ; + if(pos != string::npos)return true ; + } + return false ; +} ;