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.
matchLine.cpp
- Committer:
- takashikojo
- Date:
- 2015-10-23
- Revision:
- 5:6105553963bb
- Parent:
- 4:acfd6fbf9f9e
- Child:
- 6:d4d781f31f70
File content as of revision 5:6105553963bb:
#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) ; } fclose(fp) ; 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 ; } ;