Commit ef4dfb29 authored by Marius Rackwitz's avatar Marius Rackwitz

Add helper method Target#c99ext_identifier

parent 93ddfa2a
......@@ -177,5 +177,21 @@ module Pod
end
#-------------------------------------------------------------------------#
protected
# Transforms the given string into a valid +identifier+ after C99ext
# standard, so that it can be used in source code where escaping of
# ambiguous characters is not applicable.
#
# @param [String] name
# any name, which may contain leading numbers, spaces or invalid
# characters.
#
# @return [String]
#
def c99ext_identifier(name)
name.gsub(/^([0-9])/, '_\1').gsub(/[^a-zA-Z0-9_]/, '_')
end
end
end
......@@ -3,5 +3,20 @@ require File.expand_path('../../spec_helper', __FILE__)
module Pod
describe Target do
describe '#c99ext_identifier' do
before do
@target = Target.new
end
it 'should mask, but keep leading numbers' do
@target.send(:c99ext_identifier, '123BananaLib').should == '_123BananaLib'
end
it 'should mask invalid chars' do
@target.send(:c99ext_identifier, 'iOS-App BânánàLïb').should == 'iOS_App_B_n_n_L_b'
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment