blob: f80cfc12bb0ac498d78da9fd6b1b4b6fe6eef5fe (
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 = strlen(haystack);
int nlen = strlen(needle);
if (hlen >= nlen)
{
lua_pushboolean(L, strcmp(haystack + hlen - nlen, needle) == 0);
return 1;
}
}
return 0;
}
|