file_util.cpp

来自「一个开源的嵌入式flash播放器的源代码」· C++ 代码 · 共 55 行

CPP
55
字号
// file_util.cpp	-- Thatcher Ulrich <tu@tulrich.com> 2005

// This source code has been donated to the Public Domain.  Do
// whatever you want with it.

// A file class that can be customized with callbacks.


#include "base/file_util.h"
#include "base/utility.h"
#include <string.h>


static const char* reverse_scan(const char* begin, const char* end, char c)
// Scans in reverse, from *(end-1) through *begin, until it finds a
// character matching c.  If none is found, returns end, else returns
// a pointer to the char.
{
	assert(begin <= end);
	
	const char* p = end;
	while (p > begin) {
		p--;
		if (*p == c) {
			return p;
		}
	}

	return end;
}


const char* file_util::get_extension(const char* path)
{
	int len = strlen(path);
	const char* last_dot = reverse_scan(path, path + len, '.');
	const char* last_slash = reverse_scan(last_dot, path + len, '/');

	if (last_dot[0] && last_slash[0] == 0) {
		return last_dot + 1;
	}

	// No apparent file extension, return an empty string.
	return path + len;
}



// Local Variables:
// mode: C++
// c-basic-offset: 8 
// tab-width: 8
// indent-tabs-mode: t
// End:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?