Skip to content

Instantly share code, notes, and snippets.

@sritasngh
Created June 19, 2021 10:48
Show Gist options
  • Save sritasngh/c0bc32b2895ae67540d8eeabdb4e418b to your computer and use it in GitHub Desktop.
Save sritasngh/c0bc32b2895ae67540d8eeabdb4e418b to your computer and use it in GitHub Desktop.
This code works to find starting and ending pointer to highlight matched license text as scanned by scancode.
unsigned long getFilePointer(const string& filename,
size_t start_line,
const string& match_text){
ifstream checkfile(filename);
string str;
if(checkfile.is_open()){
for (size_t i = 0; i <start_line-1; i++)
{
getline(checkfile, str);
}
int file_p = checkfile.tellg();
getline(checkfile, str);
cout<< "Checkline="<<str<<"\n";
unsigned int pos= str.find(match_text);
if(pos!=string::npos){
return file_p+pos;
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment