summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/genie/src/host/string_endswith.c
blob: 8e3cd8970ebc9adc51b996860abd7c7d4114b9df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
 * \file   string_endswith.c
 * \brief  Determines if a string ends with the given sequence.
 * \author Copyright (c) 2002-2009 Jason Perkins and the Premake project
 */

#include "premake.h"
#include <string.h>


int string_endswith(lua_State* L)
{
	const char* haystack = luaL_optstring(L, 1, NULL);
	const char* needle   = luaL_optstring(L, 2, NULL);

	if (haystack && needle)
	{
		int hlen = (int)strlen(haystack);
		int nlen = (int)strlen(needle);
		if (hlen >= nlen)
		{
			lua_pushboolean(L, strcmp(haystack + hlen - nlen, needle) == 0);
			return 1;
		}
	}

	return 0;
}