Skip to content

Commit

Permalink
Merge branch 'release-1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Apr 25, 2014
2 parents 36186af + a92ab33 commit e6f7dd8
Show file tree
Hide file tree
Showing 14 changed files with 400 additions and 13 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
language: objective-c

before_script:
- sudo easy_install cpp-coveralls

script:
- xctool -project genstrings2.xcodeproj -scheme "Static Library" test -arch x86_64 ONLY_ACTIVE_ARCH=NO
### disabled until Travis-CI fixes missing appledoc install on 10.9 machines
# - appledoc -o /tmp .

after_success:
- ./coveralls.rb --extension m --exclude-folder Demo --exclude-folder Test --exclude-folder Externals
2 changes: 2 additions & 0 deletions Core/Source/DTLocalizableStringAggregator.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ - (id)init

- (void)dealloc
{
#if !OS_OBJECT_USE_OBJC
dispatch_release(_tableQueue);
dispatch_release(_tableGroup);
#endif
}

- (void)setCustomMacroPrefix:(NSString *)customMacroPrefix
Expand Down
2 changes: 1 addition & 1 deletion Core/Source/DTLocalizableStringEntry.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ - (void)addComment:(NSString *)comment
comment = [self _stringByRecognizingNil:comment];

// remove the quotes
comment = [comment stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\""]];
comment = [comment stringByRemovingSurroundingQuotes];

if (![comment length])
{
Expand Down
7 changes: 7 additions & 0 deletions Core/Source/NSString+DTLocalizableStringScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@
@returns The receiver's content with control characters slash-escaped
*/
- (NSString *)stringByAddingSlashEscapes;

/**
Change "foo" to foo. This will remove just one set of quotes, so that e.g. ""foo"" becomes "foo"
If the string does not begin and end with a quote, returns it unmodified.
@returns The string with one set of surrounding quotes removed.
*/
- (NSString *)stringByRemovingSurroundingQuotes;
@end
14 changes: 13 additions & 1 deletion Core/Source/NSString+DTLocalizableStringScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ - (NSString *)stringByNumberingFormatPlaceholders
static dispatch_once_t onceToken;
static NSRegularExpression *matchNonEscapedPercent = nil;
dispatch_once(&onceToken, ^{
matchNonEscapedPercent = [NSRegularExpression regularExpressionWithPattern:@"(?<=[^%]|^)(?:(?:%%)*)(%)(?:[^%]|$)" options:0 error:NULL];
matchNonEscapedPercent = [NSRegularExpression regularExpressionWithPattern:@"(?<=[^%]|^)(?:(?:%%)*)(%(?!\\d+\\$))(?:[^%]|$)" options:0 error:NULL];
});

__block NSMutableString *tmpString = nil;
Expand Down Expand Up @@ -618,4 +618,16 @@ - (NSString *)stringByAddingSlashEscapes
return clean;
}

- (NSString *)stringByRemovingSurroundingQuotes
{
NSUInteger length = [self length];
NSString *clean = self;

if (length >= 2 && [self characterAtIndex:0] == '\"' && [self characterAtIndex:length-1] == '\"') {
clean = [self substringWithRange:NSMakeRange(1, length-2)];
}

return clean;
}

@end
15 changes: 15 additions & 0 deletions DTLocalizableStringScanner.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Pod::Spec.new do |spec|
spec.name = 'DTLocalizableStringScanner'
spec.version = '1.0.0'
spec.platform = :osx, '10.7'
spec.license = 'BSD'
spec.source = { :git => 'https://github.com/Cocoanetics/DTLocalizableStringScanner.git', :tag => spec.version.to_s }
spec.source_files = 'Core/Source/*.{h,m,c}'
spec.requires_arc = true
spec.homepage = 'https://github.com/Cocoanetics/DTLocalizableStringScanner'
spec.summary = 'A better performing multi-threaded replacement for genstrings as component you can use in your own apps scanning for localizable strings.'
spec.author = { 'Oliver Drobnik' => '[email protected]' }
spec.documentation_url = 'docs.cocoanetics.com/DTLocalizableStringScanner'
spec.social_media_url = 'https://twitter.com/cocoanetics'
end

2 changes: 2 additions & 0 deletions Readme.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
DTLocalizableStringScanner
==========================

[![Build Status](https://travis-ci.org/Cocoanetics/DTLocalizableStringScanner.png?branch=develop)](https://travis-ci.org/Cocoanetics/DTLocalizableStringScanner) [![Coverage Status](https://coveralls.io/repos/Cocoanetics/DTLocalizableStringScanner/badge.png?branch=develop)](https://coveralls.io/r/Cocoanetics/DTLocalizableStringScanner?branch=develop)

This project aims to duplicate and enhance the functionality found in the `genstrings` utility provided by Apple. The Demo builds a command line utility `genstrings2` which works like the original but using more modern techniques. The Core contains classes and categories to add this scanning functionality to [Linguan](http://www.cocoanetics.com/apps/linguan/).

Documentation
Expand Down
11 changes: 11 additions & 0 deletions Test/Resources/Multiple_Parts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Issue 7: A string can span multiple lines */

NSString *multiLine = NSLocalizedString(@"Here is one line!"
"And another"
"And yet another", @"Multiple Lines");


/* Issue 10: A string can have multiple parts */

NSLocalizedString(@"foo " @"bar", @"Test multi-part quoted strings");

4 changes: 3 additions & 1 deletion Test/Resources/Slashes_and_Quotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* Tests if the escaping of double quotes and slashes works */

NSLocalizedString(@"here are three \\\\\\\"\"\"\nslashes&quotes: \\\\\\\"\"\"", nil)
NSLocalizedString(@"here are three \\\\\\\"\"\"\nslashes&quotes: \\\\\\\"\"\"", nil)

NSLocalizedString(@"bar", @"Test comment ending with \"quotes\"");
2 changes: 2 additions & 0 deletions Test/Resources/Testcases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ NSString *message = [NSString stringWithFormat:NSLocalizedString(@"\"%@\" has be

NSLocalizedString(@"%@ had been successfully added to the Address Book.\nWould you like to edit the card now?", nil);

NSLocalizedString(@"Item %1$d of %2$d", @"Test positional params");

// some regular test cases


Expand Down
6 changes: 4 additions & 2 deletions Test/Source/UnitTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ - (void)internalTestCaseWithURL:(NSURL *)URL withTempPath:(NSString *)tempPath
NSString *genstrings1Contents = [NSString stringWithContentsOfFile:genstrings1File usedEncoding:NULL error:NULL];
NSString *genstrings2Contents = [NSString stringWithContentsOfFile:genstrings2File usedEncoding:NULL error:NULL];

// size check does not work because predicate editor output repeats comment for each token
// STAssertEquals([genstrings1Contents length], [genstrings2Contents length], @"Different file sizes on %@", genstrings1File);
// size check does not work because predicate editor output repeats comment for each token
if (![[URL absoluteString] hasSuffix:@"NSPredicateEditor.txt"]) {
STAssertEquals([genstrings1Contents length], [genstrings2Contents length], @"Different file sizes on %@", genstrings1File);
}

NSDictionary *genstrings1Stuff = [genstrings1Contents propertyListFromStringsFileFormat];
NSDictionary *genstrings2Stuff = [genstrings2Contents propertyListFromStringsFileFormat];
Expand Down
136 changes: 136 additions & 0 deletions coveralls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env ruby

require 'etc'
require 'fileutils'
require 'find'
require 'optparse'

# arraw of source subfolders to exclude
excludedFolders = []
extensionsToProcess = []
coveralls_cmd = "coveralls"

excludeHeaders = false

# create option parser
opts = OptionParser.new
opts.banner = "Usage: coveralls.rb [options]"

opts.on('-e', '--exclude-folder FOLDER', 'Folder to exclude') do |v|
excludedFolders << v
coveralls_cmd.concat(" -e #{v}")
end

opts.on('-h', '--exclude-headers', 'Ignores headers') do |v|
excludeHeaders = true
end

opts.on('-x', '--extension EXT', 'Source file extension to process') do |v|
extensionsToProcess << v
coveralls_cmd.concat(" -x #{v}")
end

opts.on_tail("-?", "--help", "Show this message") do
puts opts
exit
end

# parse the options
begin
opts.parse!(ARGV)
rescue OptionParser::InvalidOption => e
puts e
puts opts
exit(1)
end

# the folders
workingDir = Dir.getwd
derivedDataDir = "#{Etc.getpwuid.dir}/Library/Developer/Xcode/DerivedData/"
outputDir = workingDir + "/gcov"

# create gcov output folder
FileUtils.mkdir outputDir

# pattern to get source file from first line of gcov file
GCOV_SOURCE_PATTERN = Regexp.new(/Source:(.*)/)

# enumerate all gcda files underneath derivedData
Find.find(derivedDataDir) do |gcda_file|

if gcda_file.match(/\.gcda\Z/)

#get just the folder name
gcov_dir = File.dirname(gcda_file)

# cut off absolute working dir to get relative source path
relative_input_path = gcda_file.slice(derivedDataDir.length, gcda_file.length)
puts "\nINPUT: #{relative_input_path}"

#process the file
result = %x( gcov '#{gcda_file}' -o '#{gcov_dir}' )

# filter the resulting output
Dir.glob("*.gcov") do |gcov_file|

firstLine = File.open(gcov_file).readline
match = GCOV_SOURCE_PATTERN.match(firstLine)

if (match)

source_path = match[1]

puts "source: #{source_path} - #{workingDir}"

if (source_path.start_with? workingDir)

# cut off absolute working dir to get relative source path
relative_path = source_path.slice(workingDir.length+1, source_path.length)

extension = File.extname(relative_path)
extension = extension.slice(1, extension.length-1)

puts "#{extension}"

# get the path components
path_comps = relative_path.split(File::SEPARATOR)

shouldProcess = false
exclusionMsg =""

if (excludedFolders.include?(path_comps[0]))
exclusionMsg = "excluded via option"
else
if (excludeHeaders == true && extension == 'h')
exclusionMsg = "excluded header"
else
if (extensionsToProcess.count == 0 || extensionsToProcess.include?(extension))
shouldProcess = true
else
exclusionMsg = "excluded extension"
shouldProcess = false
end
end
end

if (shouldProcess)
puts " - process: #{relative_path}"
FileUtils.mv(gcov_file, outputDir)
else
puts " - ignore: #{relative_path} (#{exclusionMsg})"
FileUtils.rm gcov_file
end
else
puts " - ignore: #{gcov_file} (outside source folder)"
FileUtils.rm gcov_file
end
end
end
end
end

#call the coveralls, exclude some files
system coveralls_cmd

#clean up
FileUtils.rm_rf outputDir
Loading

0 comments on commit e6f7dd8

Please sign in to comment.