Dealing with NULL and string

I have the following function:

string ofApp::extension_from_file(string file) {
	
	int index = file.find_last_of('.');

	if (index != -1) {
		string extension = file.substr(index+1);
		extension = ofToLower(extension);
		return extension;
	}
	return NULL;
}

I have a problem in another part where I try:

if (extension != NULL) {

I get a:

comparison between NULL and non-pointer

What would be a good way to resolve this?
I could return a empty string, a pointer and maybe something else. But I have problems making a decision based on good reasoning.

These suggestions seem to make sense:

string s;

if (s.empty())

or 

if(s.size() == 0)

Related:

What about using getExtension()?

https://openframeworks.cc//documentation/utils/ofFile/#!show_getExtension

But I noticed an issue:

ofFile f2 {"duck.tar.gz"};
cout << f2.getExtension() << endl;

ofFile f0 {"duck"};
cout << f0.getExtension() << endl;

ofFile f1 {"duck.xml"};
cout << f1.getExtension() << endl;

// output:
//gz
//
//xml

So it returns empty when no extension, and arguably the wrong extension for .tar.gz. You’re code would do the same. I don’t know what is right. What if the file names is one.of.the.best.jpg? :slight_smile:

Update: maybe it’s the right thing after all, you could process the gz first, and then untar it, right?