Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions garrysmod/lua/includes/extensions/string.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

local string = string
local string_sub = string.sub
local math = math

--[[---------------------------------------------------------
Expand Down Expand Up @@ -83,15 +84,14 @@ end
local totable = string.ToTable
local string_sub = string.sub
local string_find = string.find
local string_len = string.len
function string.Explode( separator, str, withpattern )
if ( separator == "" ) then return totable( str ) end
if ( withpattern == nil ) then withpattern = false end

local ret = {}
local current_pos = 1

for i = 1, string_len( str ) do
for i = 1, #str do
local start_pos, end_pos = string_find( str, separator, current_pos, not withpattern )
if ( not start_pos ) then break end
ret[ i ] = string_sub( str, current_pos, start_pos - 1 )
Expand Down Expand Up @@ -323,14 +323,16 @@ end

function string.StartsWith( str, start )

return string.sub( str, 1, string.len( start ) ) == start
local n = #start
return n == 0 or string_sub(str, 1, n) == start

end
string.StartWith = string.StartsWith

function string.EndsWith( str, endStr )

return endStr == "" or string.sub( str, -string.len( endStr ) ) == endStr
local n = #endStr
return n == 0 or string_sub(str, -n) == endStr

end

Expand Down