From Dark and Darker Wiki

Overview

Utility functions

Functions

insert_space_before_capitals

Adds spaces before capital letters (other than if its the first character). i.e. "ElementalBolt" -> "Elemental Bolt"

Can be invoked within wikitext, or called within another lua module. See Module:MergeSpells for an example that utilizes this module.

Parameters

  • input_text - input string

Examples

{{#invoke:Utilities|insert_space_before_capitals|ElementalBolt}}

Elemental Bolt


local p = {}

function p.insert_space_before_capitals(input_text)
	if type(input_text) == "table" and input_text.args then -- if called via wikitext instead of lua
        local frame = input_text
        input_text = frame.args[1]
	end

    -- Add a space before each capital letter that is not the first character
    local output_text = input_text:gsub("(%S)(%u)", "%1 %2")
    return output_text
end

return p