//Example Shebang: #!/usr/bin/perl
//Example Shebam: #:utf8
//Example Shebam: #:ascii
//Example Shebam: #:b64encrypt
//Example Shebam: #:gtk+xml-gladed6
//Example Shebam: #:xml-myprogram
//Example Shebamshebang: #:perl-ascii!/usr/bin/perl
//Example Shebamshebang: #:perl-ascii!c:/perl/bin/perl.exe
//Example Shebamshebang: #:perl-ascii!c:/perl/bin/perl.exe
//utf16, utf32?? who cares... utf8 already won... 99% of the time... except for legacy windows code...
inline void ShebamWrite(ofstream& myfile, const string Shebam) {
myfile <<"#:" << Shebam << "\n";
}
//Shebam: A File 'Bom' the way it should have been done.
inline string ShebamCheck(string filename) {
ifstream myfile(filename);
string Shebam = ShebamRead(myfile);
myfile.close();
return Shebam;
}
inline string ShebamRead(ifstream& myfile) {
string buffer;
getline(myfile, buffer);
int len = buffer.size();
if (len < 2)
return string{};
bool found=false;
if ((buffer[0]=='#') && ((buffer[1]==':') || (buffer[1]=='!'))) {
for(int i=2; i < len; i++) {
if (!isprint(buffer[i])) {
found=false;
break;
}
else if (i>3) { //need at least one bom character
found=true;
}
}
}
if (!found) {
return string{};
}
buffer.erase(0, 2);
return buffer;
}
int main(int argc, char** argv) {
string shabam1 = ShebamCheck("myfile1.txt");
if (shabam1 == string{}) {
cout << "shebam1 = none\n";
}
else {
cout << "shebam1 = " << shebam1 << "\n";
}
return 0;
}