diff --git a/Example/BonMot.xcodeproj/project.pbxproj b/Example/BonMot.xcodeproj/project.pbxproj index d760300f..33cd9420 100644 --- a/Example/BonMot.xcodeproj/project.pbxproj +++ b/Example/BonMot.xcodeproj/project.pbxproj @@ -64,12 +64,13 @@ CD6DF05A1BF6B98500676E2D /* NSDictionary+BONEquality.m in Sources */ = {isa = PBXBuildFile; fileRef = CD6DF04F1BF6B53100676E2D /* NSDictionary+BONEquality.m */; }; CD78701E1CA5F8EC00B2714F /* EBGaramond12-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = CD6DF03E1BF6AFAA00676E2D /* EBGaramond12-Regular.otf */; }; CDE658581C24ADD8009C7D09 /* BONUnderlineAndStrikethroughTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE658571C24ADD8009C7D09 /* BONUnderlineAndStrikethroughTestCase.m */; }; - EC2F199E1CEA324900D9F1FE /* BONTagDictionaryStylesTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = EC2F199C1CEA324300D9F1FE /* BONTagDictionaryStylesTestCase.m */; }; - EC433DB31C88B7D9001B3ABE /* BONTagStylesTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = EC433DB11C88B65B001B3ABE /* BONTagStylesTestCase.m */; }; + EC2F199E1CEA324900D9F1FE /* BONTagStylesTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = EC2F199C1CEA324300D9F1FE /* BONTagStylesTestCase.m */; }; + EC2F19A11CEBBAF900D9F1FE /* BONTagTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = EC2F199F1CEBBA9E00D9F1FE /* BONTagTestCase.m */; }; + EC433DB31C88B7D9001B3ABE /* BONTagMakeTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = EC433DB11C88B65B001B3ABE /* BONTagMakeTestCase.m */; }; EC433DB61C88BBDE001B3ABE /* BONUIKitUtilitiesTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = EC433DB41C88BBDB001B3ABE /* BONUIKitUtilitiesTestCase.m */; }; EC433DB91C88DE5F001B3ABE /* TagStylesCell.m in Sources */ = {isa = PBXBuildFile; fileRef = EC433DB81C88DE5F001B3ABE /* TagStylesCell.m */; }; EC433DBB1C88DEF7001B3ABE /* TagStylesCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = EC433DBA1C88DEF7001B3ABE /* TagStylesCell.xib */; }; - ECD4DB6B1CE3EA2700079675 /* BONTagComplexStylesTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = ECD4DB691CE3EA1F00079675 /* BONTagComplexStylesTestCase.m */; }; + ECD4DB6B1CE3EA2700079675 /* BONTagComplexMakeTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = ECD4DB691CE3EA1F00079675 /* BONTagComplexMakeTestCase.m */; }; F6E9CEC93164745FB8BEB8FC /* Pods_BonMot_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E8BB0552A748FFBA2BD0BE4 /* Pods_BonMot_Example.framework */; }; /* End PBXBuildFile section */ @@ -169,13 +170,14 @@ CDE658571C24ADD8009C7D09 /* BONUnderlineAndStrikethroughTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONUnderlineAndStrikethroughTestCase.m; sourceTree = ""; }; CFD6D97A946F2FEF294F4BBB /* Pods_BonMot_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_BonMot_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; EBE7037465B0F6F184875C40 /* Pods-BonMot_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BonMot_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-BonMot_Example/Pods-BonMot_Example.release.xcconfig"; sourceTree = ""; }; - EC2F199C1CEA324300D9F1FE /* BONTagDictionaryStylesTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONTagDictionaryStylesTestCase.m; sourceTree = ""; }; - EC433DB11C88B65B001B3ABE /* BONTagStylesTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONTagStylesTestCase.m; sourceTree = ""; }; + EC2F199C1CEA324300D9F1FE /* BONTagStylesTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONTagStylesTestCase.m; sourceTree = ""; }; + EC2F199F1CEBBA9E00D9F1FE /* BONTagTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONTagTestCase.m; sourceTree = ""; }; + EC433DB11C88B65B001B3ABE /* BONTagMakeTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONTagMakeTestCase.m; sourceTree = ""; }; EC433DB41C88BBDB001B3ABE /* BONUIKitUtilitiesTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONUIKitUtilitiesTestCase.m; sourceTree = ""; }; EC433DB71C88DE5F001B3ABE /* TagStylesCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagStylesCell.h; sourceTree = ""; }; EC433DB81C88DE5F001B3ABE /* TagStylesCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TagStylesCell.m; sourceTree = ""; }; EC433DBA1C88DEF7001B3ABE /* TagStylesCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TagStylesCell.xib; sourceTree = ""; }; - ECD4DB691CE3EA1F00079675 /* BONTagComplexStylesTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONTagComplexStylesTestCase.m; sourceTree = ""; }; + ECD4DB691CE3EA1F00079675 /* BONTagComplexMakeTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONTagComplexMakeTestCase.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -290,9 +292,10 @@ CD6DEFDA1BF6ADF900676E2D /* BONDictionaryEqualityTestCase.m */, 730361E11C9B5CD300987809 /* BONHumanReadableStringTestCase.m */, CD6DEFDB1BF6ADF900676E2D /* BONIndentSpacerTestCase.m */, - EC433DB11C88B65B001B3ABE /* BONTagStylesTestCase.m */, - EC2F199C1CEA324300D9F1FE /* BONTagDictionaryStylesTestCase.m */, - ECD4DB691CE3EA1F00079675 /* BONTagComplexStylesTestCase.m */, + EC2F199C1CEA324300D9F1FE /* BONTagStylesTestCase.m */, + EC433DB11C88B65B001B3ABE /* BONTagMakeTestCase.m */, + ECD4DB691CE3EA1F00079675 /* BONTagComplexMakeTestCase.m */, + EC2F199F1CEBBA9E00D9F1FE /* BONTagTestCase.m */, CD6DEFDC1BF6ADF900676E2D /* BONPropertyClobberingTestCase.m */, CD6DEFDD1BF6ADF900676E2D /* BONTextAlignmentConstraintTestCase.m */, CD6DEFDE1BF6ADF900676E2D /* BONTextAlignmentTestCase.m */, @@ -641,16 +644,17 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - EC2F199E1CEA324900D9F1FE /* BONTagDictionaryStylesTestCase.m in Sources */, + EC2F199E1CEA324900D9F1FE /* BONTagStylesTestCase.m in Sources */, EC433DB61C88BBDE001B3ABE /* BONUIKitUtilitiesTestCase.m in Sources */, + EC2F19A11CEBBAF900D9F1FE /* BONTagTestCase.m in Sources */, CD6DF05A1BF6B98500676E2D /* NSDictionary+BONEquality.m in Sources */, CD6DF04B1BF6B37E00676E2D /* DummyAssetClass.m in Sources */, 730361E31C9B5CDD00987809 /* BONHumanReadableStringTestCase.m in Sources */, - ECD4DB6B1CE3EA2700079675 /* BONTagComplexStylesTestCase.m in Sources */, + ECD4DB6B1CE3EA2700079675 /* BONTagComplexMakeTestCase.m in Sources */, CD6DEFED1BF6ADF900676E2D /* BONPropertyClobberingTestCase.m in Sources */, CD6DEFF11BF6ADF900676E2D /* BONTextAlignmentTestCase.m in Sources */, CD6DEFE11BF6ADF900676E2D /* BONBaseTestCase.m in Sources */, - EC433DB31C88B7D9001B3ABE /* BONTagStylesTestCase.m in Sources */, + EC433DB31C88B7D9001B3ABE /* BONTagMakeTestCase.m in Sources */, CDE658581C24ADD8009C7D09 /* BONUnderlineAndStrikethroughTestCase.m in Sources */, CD6DEFF31BF6ADF900676E2D /* BONTrackingTestCase.m in Sources */, CD64F15E1CA4DAC800042559 /* BONFigureTestCase.m in Sources */, diff --git a/Example/BonMot.xcodeproj/xcshareddata/xcschemes/BonMot-Example.xcscheme b/Example/BonMot.xcodeproj/xcshareddata/xcschemes/BonMot-Example.xcscheme index 5fe6e4d7..301b5c4c 100644 --- a/Example/BonMot.xcodeproj/xcshareddata/xcschemes/BonMot-Example.xcscheme +++ b/Example/BonMot.xcodeproj/xcshareddata/xcschemes/BonMot-Example.xcscheme @@ -28,7 +28,7 @@ buildForAnalyzing = "YES"> diff --git a/Example/BonMot/Cells/TagStylesCell.m b/Example/BonMot/Cells/TagStylesCell.m index 846db5cd..71e28e6f 100644 --- a/Example/BonMot/Cells/TagStylesCell.m +++ b/Example/BonMot/Cells/TagStylesCell.m @@ -29,8 +29,9 @@ - (void)awakeFromNib BONChain *italicChain = BONChain.new.fontNameAndSize(@"Baskerville-Italic", 15); BONChain *baseChain = BONChain.new.fontNameAndSize(@"Baskerville", 17) - .tagStyles(@[ BONTagMake(@"bold", boldChain), BONTagMake(@"italic", italicChain) ]) - .string(@"This text is wrapped in a \\ tag.\nThis text is wrapped in an \\ tag."); + .tagStyles(@{ @"bold" : boldChain, + @"italic" : italicChain }) + .string(@"This text contains a \\ tag.\nThis text contains an \\ tag."); self.label.attributedText = baseChain.attributedString; diff --git a/Example/Tests/BONTagComplexStylesTestCase.m b/Example/Tests/BONTagComplexMakeTestCase.m similarity index 97% rename from Example/Tests/BONTagComplexStylesTestCase.m rename to Example/Tests/BONTagComplexMakeTestCase.m index 1cc85468..6240d000 100644 --- a/Example/Tests/BONTagComplexStylesTestCase.m +++ b/Example/Tests/BONTagComplexMakeTestCase.m @@ -1,20 +1,20 @@ // -// BONTagComplexStylingTestCase.m +// BONTagComplexMakeTestCase.m // BonMot // // Created by Nora Trapp on 3/3/16. -// +// Copyright © 2016 Zev Eisenberg. All rights reserved. // #import "BONBaseTestCase.h" @import BonMot; -@interface BONTagComplexStylingTestCase : BONBaseTestCase +@interface BONTagComplexMakeTestCase : BONBaseTestCase @end -@implementation BONTagComplexStylingTestCase +@implementation BONTagComplexMakeTestCase - (void)testSingleTagSingleStyle { @@ -373,9 +373,9 @@ - (void)testNestedEscapedEndTag - (void)testInterleavedEscapedEndTag { - BONChain *chain = BONChain.new.string(@"qwerty[/b]qwerty[/i]qwerty[/b](i)Helloqwerty[/i][/i], world!") + BONChain *chain = BONChain.new.string(@"qwerty[/b]asdfgh[/i]qwerty[/b](i)Helloasdfgh[/i][/i], world!") .tagComplexStyles(@[ - BONTagComplexMake(@"(i)", @"[/i]", @"qwerty", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagComplexMake(@"(i)", @"[/i]", @"asdfgh", BONChain.new.font([UIFont italicSystemFontOfSize:16])), BONTagComplexMake(@"(b)", @"[/b]", @"qwerty", BONChain.new.font([UIFont boldSystemFontOfSize:16])), ]); diff --git a/Example/Tests/BONTagDictionaryStylesTestCase.m b/Example/Tests/BONTagMakeTestCase.m similarity index 77% rename from Example/Tests/BONTagDictionaryStylesTestCase.m rename to Example/Tests/BONTagMakeTestCase.m index 49ad0758..61d219da 100644 --- a/Example/Tests/BONTagDictionaryStylesTestCase.m +++ b/Example/Tests/BONTagMakeTestCase.m @@ -1,8 +1,8 @@ // -// BONTagDictionaryStylesTestCase.m +// BONTagMakeTestCase.m // BonMot // -// Created by Nora Trapp on 5/16/16. +// Created by Nora Trapp on 3/3/16. // Copyright © 2016 Zev Eisenberg. All rights reserved. // @@ -10,16 +10,16 @@ @import BonMot; -@interface BONTagDictionaryStylesTestCase : BONBaseTestCase +@interface BONTagMakeTestCase : BONBaseTestCase @end -@implementation BONTagDictionaryStylesTestCase +@implementation BONTagMakeTestCase - (void)testSingleTagSingleStyle { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagStyles(@{ @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]) }); + .tagComplexStyles(@[ BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])) ]); NSAttributedString *attributedString = chain.attributedString; @@ -48,7 +48,7 @@ - (void)testSingleTagSingleStyle - (void)testMultipleTagsSingleStyle { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagStyles(@{ @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]) }); + .tagComplexStyles(@[ BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])) ]); NSAttributedString *attributedString = chain.attributedString; @@ -82,10 +82,10 @@ - (void)testMultipleTagsSingleStyle - (void)testSingleTagMultipleStyles { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; @@ -114,10 +114,10 @@ - (void)testSingleTagMultipleStyles - (void)testMultipleTagsMultipleStyles { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; @@ -151,10 +151,10 @@ - (void)testMultipleTagsMultipleStyles - (void)testInterleavedTags { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; @@ -179,10 +179,10 @@ - (void)testInterleavedTags - (void)testNestedTags { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; @@ -207,10 +207,10 @@ - (void)testNestedTags - (void)testMixedOrdering { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; @@ -250,10 +250,10 @@ - (void)testMixedOrdering - (void)testEscapedStartTag { BONChain *chain = BONChain.new.string(@"\\Hello, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; @@ -282,10 +282,10 @@ - (void)testEscapedStartTag - (void)testMultipleEscapedStartTag { BONChain *chain = BONChain.new.string(@"\\Hello\\, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; @@ -314,10 +314,10 @@ - (void)testMultipleEscapedStartTag - (void)testMultipleEscapedEndTag { BONChain *chain = BONChain.new.string(@"\\Hello\\, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; @@ -346,10 +346,10 @@ - (void)testMultipleEscapedEndTag - (void)testNestedEscapedEndTag { BONChain *chain = BONChain.new.string(@"Hello\\, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; @@ -374,10 +374,10 @@ - (void)testNestedEscapedEndTag - (void)testInterleavedEscapedEndTag { BONChain *chain = BONChain.new.string(@"\\\\\\Hello\\, world!") - .tagStyles(@{ - @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), - @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), - }); + .tagComplexStyles(@[ + BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), + BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), + ]); NSAttributedString *attributedString = chain.attributedString; diff --git a/Example/Tests/BONTagStylesTestCase.m b/Example/Tests/BONTagStylesTestCase.m index 4d6670b0..41e0a2ea 100644 --- a/Example/Tests/BONTagStylesTestCase.m +++ b/Example/Tests/BONTagStylesTestCase.m @@ -2,8 +2,8 @@ // BONTagStylesTestCase.m // BonMot // -// Created by Nora Trapp on 3/3/16. -// +// Created by Nora Trapp on 5/16/16. +// Copyright © 2016 Zev Eisenberg. All rights reserved. // #import "BONBaseTestCase.h" @@ -19,7 +19,7 @@ @implementation BONTagStylesTestCase - (void)testSingleTagSingleStyle { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagComplexStyles(@[ BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])) ]); + .tagStyles(@{ @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]) }); NSAttributedString *attributedString = chain.attributedString; @@ -48,7 +48,7 @@ - (void)testSingleTagSingleStyle - (void)testMultipleTagsSingleStyle { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagComplexStyles(@[ BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])) ]); + .tagStyles(@{ @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]) }); NSAttributedString *attributedString = chain.attributedString; @@ -82,10 +82,10 @@ - (void)testMultipleTagsSingleStyle - (void)testSingleTagMultipleStyles { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; @@ -114,10 +114,10 @@ - (void)testSingleTagMultipleStyles - (void)testMultipleTagsMultipleStyles { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; @@ -151,10 +151,10 @@ - (void)testMultipleTagsMultipleStyles - (void)testInterleavedTags { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; @@ -179,10 +179,10 @@ - (void)testInterleavedTags - (void)testNestedTags { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; @@ -207,10 +207,10 @@ - (void)testNestedTags - (void)testMixedOrdering { BONChain *chain = BONChain.new.string(@"Hello, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; @@ -250,10 +250,10 @@ - (void)testMixedOrdering - (void)testEscapedStartTag { BONChain *chain = BONChain.new.string(@"\\Hello, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; @@ -282,10 +282,10 @@ - (void)testEscapedStartTag - (void)testMultipleEscapedStartTag { BONChain *chain = BONChain.new.string(@"\\Hello\\, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; @@ -314,10 +314,10 @@ - (void)testMultipleEscapedStartTag - (void)testMultipleEscapedEndTag { BONChain *chain = BONChain.new.string(@"\\Hello\\, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; @@ -346,10 +346,10 @@ - (void)testMultipleEscapedEndTag - (void)testNestedEscapedEndTag { BONChain *chain = BONChain.new.string(@"Hello\\, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; @@ -374,10 +374,10 @@ - (void)testNestedEscapedEndTag - (void)testInterleavedEscapedEndTag { BONChain *chain = BONChain.new.string(@"\\\\\\Hello\\, world!") - .tagComplexStyles(@[ - BONTagMake(@"i", BONChain.new.font([UIFont italicSystemFontOfSize:16])), - BONTagMake(@"b", BONChain.new.font([UIFont boldSystemFontOfSize:16])), - ]); + .tagStyles(@{ + @"i" : BONChain.new.font([UIFont italicSystemFontOfSize:16]), + @"b" : BONChain.new.font([UIFont boldSystemFontOfSize:16]), + }); NSAttributedString *attributedString = chain.attributedString; diff --git a/Example/Tests/BONTagTestCase.m b/Example/Tests/BONTagTestCase.m new file mode 100644 index 00000000..eb577f01 --- /dev/null +++ b/Example/Tests/BONTagTestCase.m @@ -0,0 +1,71 @@ +// +// BONTagTestCase.m +// BonMot +// +// Created by Nora Trapp on 5/17/16. +// Copyright © 2016 Zev Eisenberg. All rights reserved. +// + +#import "BONBaseTestCase.h" +@import BonMot; + +@interface BONTag () + +@property (strong, nonatomic, BONNonnull) BONGeneric(NSMutableArray, NSValue *) * ranges; + ++ (BONNonnull BONGeneric(NSArray, NSValue *) *)escapedRangesInString:(NSString *BONCNonnull *BONCNonnull)string withTags:(BONNonnull BONGeneric(NSArray, BONTag *) *)tags; ++ (NSRange)firstOccurrenceOfString:(BONNonnull NSString *)string inString:(BONNonnull NSString *)stringToSearch ignoringRanges:(BONNonnull BONGeneric(NSArray, NSValue *) *)escapedRanges inRange:(NSRange)range; ++ (BONNonnull BONGeneric(NSArray, BONTag *) *)rangesInString:(NSString *BONCNonnull *BONCNonnull)string betweenTags:(BONNonnull BONGeneric(NSArray, BONTag *) *)tags; +@end + +@import BonMot; + +@interface BONTagTestCase : BONBaseTestCase + +@end + +@implementation BONTagTestCase + +- (void)testEscapedRangesInString +{ + NSString *string = @"This is a \\ string that \\ has \\escaped characters."; + NSArray *ranges = [BONTag escapedRangesInString:&string withTags:@[ BONTagMake(@"b", BONChain.new) ]]; + + NSString *stringWithoutEscapes = @"This is a string that has \\escaped characters."; + XCTAssertEqualObjects(string, stringWithoutEscapes); + + NSArray *escapedRanges = @[ [NSValue valueWithRange:NSMakeRange(10, 3)], [NSValue valueWithRange:NSMakeRange(26, 4)] ]; + XCTAssertEqualObjects(ranges, escapedRanges); +} + +- (void)testFirstOccurenceOfString +{ + NSString *string = @"This is a \\ string that \\ has \\escaped characters."; + NSRange range = [BONTag firstOccurrenceOfString:@"" inString:string ignoringRanges:@[] inRange:NSMakeRange(0, string.length)]; + + XCTAssertTrue(NSEqualRanges(range, NSMakeRange(11, 3))); +} + +- (void)testFirstOccurenceOfStringWithIgnoredRange +{ + NSString *string = @"This is a \\ string that \\ has \\escaped characters."; + NSArray *ignoredRanges = @[ [NSValue valueWithRange:NSMakeRange(8, 3)] ]; + NSRange range = [BONTag firstOccurrenceOfString:@"" inString:string ignoringRanges:ignoredRanges inRange:NSMakeRange(0, string.length)]; + + XCTAssertTrue(NSEqualRanges(range, NSMakeRange(15, 3))); +} + +- (void)testRangesBetweenTags +{ + NSString *string = @"This is a tagged string."; + NSArray *tags = [BONTag rangesInString:&string betweenTags:@[ BONTagMake(@"b", BONChain.new) ]]; + + NSString *stringWithoutTags = @"This is a tagged string."; + XCTAssertEqualObjects(string, stringWithoutTags); + + NSArray *tagRanges = @[ [NSValue valueWithRange:NSMakeRange(10, 6)] ]; + BONTag *resultTag = tags.firstObject; + XCTAssertEqualObjects(resultTag.ranges, tagRanges); +} + +@end diff --git a/Pod/Classes/BONChain.h b/Pod/Classes/BONChain.h index 6cec58c7..0a69a353 100644 --- a/Pod/Classes/BONChain.h +++ b/Pod/Classes/BONChain.h @@ -13,7 +13,8 @@ BON_ASSUME_NONNULL_BEGIN -@class BONChain, BONTag; +@class BONChain; +@class BONTag; typedef BONChain *BONCNonnull (^BONChainFontNameAndSize)(NSString *BONCNonnull fontName, CGFloat fontSize); typedef BONChain *BONCNonnull (^BONChainFont)(UIFont *BONCNullable font); @@ -98,8 +99,8 @@ typedef BONChain *BONCNonnull (^BONTagComplexStyles)(BONGeneric(NSArray, BONTag @property (copy, nonatomic, readonly) BONChainStrikethroughColor strikethroughColor; /** - * Assign @p BONTextables to use in styling substrings surrounded in given tags. - * For example, ["b": boldTextable] would apply the @p boldChain + * Assign @p BONTextables to use in styling substrings surrounded by given tags. + * For example, ["b": boldChain] would apply the @p boldChain * to any substring surrounded by and remove the tags from the resulting * attributed string. Nested tagging is not supported. */ diff --git a/Pod/Classes/BONChain.m b/Pod/Classes/BONChain.m index 33f3b16b..c49d0b44 100644 --- a/Pod/Classes/BONChain.m +++ b/Pod/Classes/BONChain.m @@ -356,7 +356,7 @@ - (BONChainStrikethroughColor)strikethroughColor - (BONTagStyles)tagStyles { - BONTagStyles tagStylesBlock = ^(NSDictionary *tagStyles) { + BONTagStyles tagStylesBlock = ^(BONGeneric(NSDictionary, NSString *, id)*tagStyles) { __typeof(self) newChain = self.copyWithoutNextText; newChain.text.tagStyles = BONTagsFromDictionary(tagStyles); return newChain; @@ -367,7 +367,7 @@ - (BONTagStyles)tagStyles - (BONTagComplexStyles)tagComplexStyles { - BONTagComplexStyles tagStylesBlock = ^(NSArray *tagStyles) { + BONTagComplexStyles tagStylesBlock = ^(BONGeneric(NSArray, BONTag *)*tagStyles) { __typeof(self) newChain = self.copyWithoutNextText; newChain.text.tagStyles = tagStyles; return newChain; diff --git a/Pod/Classes/BONTag.h b/Pod/Classes/BONTag.h index d7c7fc60..a1ad8f18 100644 --- a/Pod/Classes/BONTag.h +++ b/Pod/Classes/BONTag.h @@ -1,9 +1,9 @@ // // BONTag.h -// Pods +// BonMot // // Created by Nora Trapp on 5/11/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // #import @@ -33,20 +33,24 @@ * * @return A @p BONTag instance representing the tag. */ -CG_INLINE BONTag *BONCNonnull BONTagComplexMake(NSString *BONCNonnull startTag, NSString *BONCNonnull endTag, NSString *BONCNonnull escapeString, id BONCNonnull textable) +NS_INLINE BONTag *BONCNonnull BONTagComplexMake(NSString *BONCNonnull startTag, NSString *BONCNonnull endTag, NSString *BONCNonnull escapeString, id BONCNonnull textable) { return [[BONTag alloc] initWithStartTag:startTag endTag:endTag escapeString:escapeString textable:textable]; } /** - * Create a tag using the default start and end formats and using \ as an escape character. + * Create a tag using the default start and end formats and using \ as an escape character. Example: + * @code + * Normal String + * String with escaped \ + * @endcode * * @param tag The tag string. * @param textable The style to apply. * * @return A @p BONTag instance representing the tag. */ -CG_INLINE BONTag *BONCNonnull BONTagMake(NSString *BONCNonnull tag, id BONCNonnull textable) +NS_INLINE BONTag *BONCNonnull BONTagMake(NSString *BONCNonnull tag, id BONCNonnull textable) { return [[BONTag alloc] initWithTag:tag textable:textable]; } @@ -54,11 +58,11 @@ CG_INLINE BONTag *BONCNonnull BONTagMake(NSString *BONCNonnull tag, id) * BONCNonnull dictionary) +NS_INLINE BONGeneric(NSArray, BONTag *) * BONCNonnull BONTagsFromDictionary(BONGeneric(NSDictionary, NSString *, id) * BONCNonnull dictionary) { NSMutableArray *tags = [NSMutableArray array]; for (NSString *key in dictionary) { diff --git a/Pod/Classes/BONTag.m b/Pod/Classes/BONTag.m index 50ed19ff..2b263091 100644 --- a/Pod/Classes/BONTag.m +++ b/Pod/Classes/BONTag.m @@ -1,19 +1,19 @@ // // BONTag.m -// Pods +// BonMot // // Created by Nora Trapp on 5/11/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // #import "BONTag_Private.h" #import "BONMot.h" -static const NSString *kBONTagDefaultStartPrefix = @"<"; -static const NSString *kBONTagDefaultStartSuffix = @">"; -static const NSString *kBONTagDefaultEndPrefix = @""; -static const NSString *kBONTagDefaultEscapeString = @"\\"; +static NSString *const kBONTagDefaultStartPrefix = @"<"; +static NSString *const kBONTagDefaultStartSuffix = @">"; +static NSString *const kBONTagDefaultEndPrefix = @""; +static NSString *const kBONTagDefaultEscapeString = @"\\"; @interface BONTag () @@ -70,15 +70,18 @@ - (NSString *)description #pragma mark - Tag Matching -+ (NSArray *)escapedRangesInString:(NSString **)string withTags:(NSArray *)tags stripEscapeCharacters:(BOOL)stripEscapeCharacters ++ (BONGeneric(NSArray, NSValue *) *)escapedRangesInString:(NSString **)string withTags:(BONGeneric(NSArray, BONTag *) *)tags { + NSParameterAssert(string); + NSParameterAssert(tags); + NSMutableArray *escapedRanges = [NSMutableArray array]; NSString *theString = *string; NSRange searchRange = NSMakeRange(0, theString.length); - // Iterate over the string finding each escape in order until there are no more escape strings + // Iterate over the string, finding each escape in order, until there are no more escape strings while (YES) { BONTag *nextTag; NSRange nextEscapeRange; @@ -113,14 +116,13 @@ + (NSArray *)escapedRangesInString:(NSString **)string withTags:(NSArray *)tags NSRange range = NSMakeRange(nextEscapeRange.location, nextEscapedTagRange.length + nextEscapeRange.length); - if (stripEscapeCharacters) { - theString = [theString stringByReplacingOccurrencesOfString:nextTag.escapeString withString:@"" options:0 range:nextEscapeRange]; - range = NSMakeRange(nextEscapeRange.location, nextEscapedTagRange.length); - } + // Strip escape characters + theString = [theString stringByReplacingOccurrencesOfString:nextTag.escapeString withString:@"" options:0 range:nextEscapeRange]; + range = NSMakeRange(nextEscapeRange.location, nextEscapedTagRange.length); [escapedRanges addObject:[NSValue valueWithRange:range]]; - searchRange = NSMakeRange(NSMaxRange(range), [theString length] - NSMaxRange(range)); + searchRange = NSMakeRange(NSMaxRange(range), theString.length - NSMaxRange(range)); } *string = theString; @@ -128,8 +130,12 @@ + (NSArray *)escapedRangesInString:(NSString **)string withTags:(NSArray *)tags return escapedRanges; } -+ (NSRange)findNextString:(NSString *)string inString:(NSString *)stringToSearch ignoringRanges:(NSArray *)escapedRanges range:(NSRange)range ++ (NSRange)firstOccurrenceOfString:(NSString *)string inString:(NSString *)stringToSearch ignoringRanges:(BONGeneric(NSArray, NSValue *) *)escapedRanges inRange:(NSRange)range { + NSParameterAssert(string); + NSParameterAssert(stringToSearch); + NSParameterAssert(escapedRanges); + NSRange searchRange = range; while (YES) { @@ -137,7 +143,7 @@ + (NSRange)findNextString:(NSString *)string inString:(NSString *)stringToSearch // Ignore this match if ([escapedRanges containsObject:[NSValue valueWithRange:stringRange]]) { - searchRange = NSMakeRange(NSMaxRange(stringRange), [stringToSearch length] - NSMaxRange(stringRange)); + searchRange = NSMakeRange(NSMaxRange(stringRange), stringToSearch.length - NSMaxRange(stringRange)); continue; } @@ -145,17 +151,20 @@ + (NSRange)findNextString:(NSString *)string inString:(NSString *)stringToSearch } } -+ (NSArray *)rangesInString:(NSString **)string betweenTags:(NSArray *)tags stripTags:(BOOL)stripTags ++ (BONGeneric(NSArray, BONTag *) *)rangesInString:(NSString **)string betweenTags:(BONGeneric(NSArray, BONTag *) *)tags { - NSArray *escapedRanges = [BONTag escapedRangesInString:string withTags:tags stripEscapeCharacters:stripTags]; + NSParameterAssert(string); + NSParameterAssert(tags); - NSArray *tagsWithRanges = [[NSArray alloc] initWithArray:tags copyItems:YES]; + BONGeneric(NSArray, NSValue *)*escapedRanges = [BONTag escapedRangesInString:string withTags:tags]; + + BONGeneric(NSArray, BONTag *)*tagsWithRanges = [[NSArray alloc] initWithArray:tags copyItems:YES]; NSString *theString = *string; NSRange searchRange = NSMakeRange(0, theString.length); - // Iterate over the string finding each tag in order until there are no more tags + // Iterate over the string, finding each tag in order, until there are no more tags while (YES) { BONTag *nextTag; NSRange nextStartTagRange; @@ -163,8 +172,8 @@ + (NSArray *)rangesInString:(NSString **)string betweenTags:(NSArray *)tags stri // Find the next start tag for (BONTag *tag in tagsWithRanges) { - NSRange startTagRange = [BONTag findNextString:tag.startTag inString:theString ignoringRanges:escapedRanges range:searchRange]; - NSRange endTagRange = [BONTag findNextString:tag.endTag inString:theString ignoringRanges:escapedRanges range:searchRange]; + NSRange startTagRange = [BONTag firstOccurrenceOfString:tag.startTag inString:theString ignoringRanges:escapedRanges inRange:searchRange]; + NSRange endTagRange = [BONTag firstOccurrenceOfString:tag.endTag inString:theString ignoringRanges:escapedRanges inRange:searchRange]; if (startTagRange.location != NSNotFound && endTagRange.location != NSNotFound) { if (!nextTag || (startTagRange.location < nextStartTagRange.location)) { nextTag = tag; @@ -180,20 +189,19 @@ + (NSArray *)rangesInString:(NSString **)string betweenTags:(NSArray *)tags stri NSRange range = NSMakeRange(NSMaxRange(nextStartTagRange), nextEndTagRange.location - NSMaxRange(nextStartTagRange)); - if (stripTags) { - range.location -= nextTag.startTag.length; + // Strip valid tags + range.location -= nextTag.startTag.length; - theString = [theString stringByReplacingOccurrencesOfString:nextTag.startTag withString:@"" options:0 range:nextStartTagRange]; - nextStartTagRange.length = 0; + theString = [theString stringByReplacingOccurrencesOfString:nextTag.startTag withString:@"" options:0 range:nextStartTagRange]; + nextStartTagRange.length = 0; - nextEndTagRange.location -= nextTag.startTag.length; - theString = [theString stringByReplacingOccurrencesOfString:nextTag.endTag withString:@"" options:0 range:nextEndTagRange]; - nextEndTagRange.length = 0; - } + nextEndTagRange.location -= nextTag.startTag.length; + theString = [theString stringByReplacingOccurrencesOfString:nextTag.endTag withString:@"" options:0 range:nextEndTagRange]; + nextEndTagRange.length = 0; [nextTag.ranges addObject:[NSValue valueWithRange:range]]; - searchRange = NSMakeRange(NSMaxRange(nextEndTagRange), [theString length] - NSMaxRange(nextEndTagRange)); + searchRange = NSMakeRange(NSMaxRange(nextEndTagRange), theString.length - NSMaxRange(nextEndTagRange)); } *string = theString; @@ -205,13 +213,11 @@ + (NSArray *)rangesInString:(NSString **)string betweenTags:(NSArray *)tags stri - (BOOL)isEqualToTag:(BONTag *)tag { - BOOL startTagEqual = [tag.startTag isEqualToString:self.startTag]; - BOOL endTagEqual = [tag.endTag isEqualToString:self.endTag]; - BOOL chainEqual = [tag.textable isEqual:self.textable]; - BOOL escapeEqual = [tag.escapeString isEqualToString:self.escapeString]; - BOOL rangesEqual = [tag.ranges isEqualToArray:self.ranges]; - - return startTagEqual && endTagEqual && chainEqual && escapeEqual && rangesEqual; + return [tag.startTag isEqualToString:self.startTag] && + [tag.endTag isEqualToString:self.endTag] && + [tag.textable isEqual:self.textable] && + [tag.escapeString isEqualToString:self.escapeString] && + [tag.ranges isEqualToArray:self.ranges]; } - (BOOL)isEqual:(id)object diff --git a/Pod/Classes/BONTag_Private.h b/Pod/Classes/BONTag_Private.h index 82928121..861f8d04 100644 --- a/Pod/Classes/BONTag_Private.h +++ b/Pod/Classes/BONTag_Private.h @@ -1,9 +1,9 @@ // // BONTag_Private.h -// Pods +// BonMot // // Created by Nora Trapp on 5/11/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // #import "BONTag.h" @@ -15,13 +15,12 @@ /** * Finds all escaped tags within a given string. * - * @param string The string to search. + * @param string The @p string to search. The @p string will be mutated to strip escape characters. * @param tags The tags to search for. - * @param stripEscapeCharacters If YES, the escape characters will be removed from the string and the resulting ranges. * * @return An array of ranges representing the escaped tags. */ -+ (BONNonnull BONGeneric(NSArray, NSValue *) *)escapedRangesInString:(NSString *BONCNonnull *BONCNonnull)string withTags:(BONNonnull BONGeneric(NSArray, BONTag *) *)tags stripEscapeCharacters:(BOOL)stripEscapeCharacters; ++ (BONNonnull BONGeneric(NSArray, NSValue *) *)escapedRangesInString:(NSString *BONCNonnull *BONCNonnull)string withTags:(BONNonnull BONGeneric(NSArray, BONTag *) *)tags; /** * Search through a string to find the next matching string that is not in an escaped range. @@ -29,21 +28,20 @@ * @param string The string to look for. * @param stringToSearch The string to search within. * @param escapedRanges The ranges to ignore matches within. - * @param range The range of @p string to search within. + * @param range The range of @p string to search. * - * @return The range of the matched string. If the string is not found, location will be NSNotFound. + * @return The range of the matched string. If the string is not found, location will be @p NSNotFound. */ -+ (NSRange)findNextString:(BONNonnull NSString *)string inString:(BONNonnull NSString *)stringToSearch ignoringRanges:(BONNonnull BONGeneric(NSArray, NSValue *) *)escapedRanges range:(NSRange)range; ++ (NSRange)firstOccurrenceOfString:(BONNonnull NSString *)string inString:(BONNonnull NSString *)stringToSearch ignoringRanges:(BONNonnull BONGeneric(NSArray, NSValue *) *)escapedRanges inRange:(NSRange)range; /** * Find all tagged strings within a given string. * - * @param string The string to search. + * @param string The @p string to search. The @p string will be mutated to strip valid tags. * @param tags The tags to search for. - * @param stripTags If YES, the start and end tags will be stripped from the string and the resulting ranges. * * @return An array of tags with the matching ranges defined. */ -+ (BONNonnull BONGeneric(NSArray, BONTag *) *)rangesInString:(NSString *BONCNonnull *BONCNonnull)string betweenTags:(BONNonnull BONGeneric(NSArray, BONTag *) *)tags stripTags:(BOOL)stripTags; ++ (BONNonnull BONGeneric(NSArray, BONTag *) *)rangesInString:(NSString *BONCNonnull *BONCNonnull)string betweenTags:(BONNonnull BONGeneric(NSArray, BONTag *) *)tags; @end diff --git a/Pod/Classes/BONText.h b/Pod/Classes/BONText.h index 65e9d4a8..ae3f6081 100644 --- a/Pod/Classes/BONText.h +++ b/Pod/Classes/BONText.h @@ -23,7 +23,8 @@ typedef NS_ENUM(NSUInteger, BONFigureSpacing) { BONFigureSpacingProportional, }; -@class BONText, BONTag; +@class BONText; +@class BONTag; @interface BONText : NSObject @@ -85,7 +86,7 @@ typedef NS_ENUM(NSUInteger, BONFigureSpacing) { @property (strong, nonatomic, BONNullable) UIColor *strikethroughColor; /** - * Assign an array of @p BONTags to use in styling substrings. + * An array of @p BONTag objects to use in styling substrings. */ @property (strong, nonatomic, BONNullable) BONGeneric(NSArray, BONTag *) * tagStyles; diff --git a/Pod/Classes/BONText.m b/Pod/Classes/BONText.m index 1ad158b7..1479af79 100644 --- a/Pod/Classes/BONText.m +++ b/Pod/Classes/BONText.m @@ -93,18 +93,18 @@ - (NSAttributedString *)attributedStringLastConcatenant:(BOOL)lastConcatenant } } else if (string) { - // If there is tag styling applied, strip the tags from the string and identify the ranges to apply the tag based chains to. - NSArray *rangesPerTag = nil; + // If there is tag styling applied, strip the tags from the string and identify the ranges to apply the tag-based chains to. + BONGeneric(NSArray, BONTag *)*rangesPerTag = nil; if (self.tagStyles) { - rangesPerTag = [BONTag rangesInString:&string betweenTags:self.tagStyles stripTags:YES]; + rangesPerTag = [BONTag rangesInString:&string betweenTags:self.tagStyles]; } mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:string attributes:self.attributes]; for (BONTag *tag in rangesPerTag) { - NSDictionary *attributes = tag.textable.text.attributes; + BONStringDict *attributes = tag.textable.text.attributes; for (NSValue *value in tag.ranges) { [mutableAttributedString setAttributes:attributes range:value.rangeValue]; } diff --git a/Pod/UIKit/BonMot+UIKit.h b/Pod/UIKit/BonMot+UIKit.h index e10f4771..656a4b5e 100644 --- a/Pod/UIKit/BonMot+UIKit.h +++ b/Pod/UIKit/BonMot+UIKit.h @@ -3,7 +3,7 @@ // BonMot // // Created by Nora Trapp on 3/10/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // #import "BONTextAlignmentConstraint.h" diff --git a/Pod/UIKit/Classes/UILabel+BonMotUtilities.h b/Pod/UIKit/Classes/UILabel+BonMotUtilities.h index 3b5aef65..ab3ad7ff 100644 --- a/Pod/UIKit/Classes/UILabel+BonMotUtilities.h +++ b/Pod/UIKit/Classes/UILabel+BonMotUtilities.h @@ -3,7 +3,7 @@ // BonMot // // Created by Nora Trapp on 3/2/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // @import UIKit; diff --git a/Pod/UIKit/Classes/UILabel+BonMotUtilities.m b/Pod/UIKit/Classes/UILabel+BonMotUtilities.m index 77766652..3969ffb7 100644 --- a/Pod/UIKit/Classes/UILabel+BonMotUtilities.m +++ b/Pod/UIKit/Classes/UILabel+BonMotUtilities.m @@ -3,7 +3,7 @@ // BonMot // // Created by Nora Trapp on 3/2/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // #import "BonMot.h" diff --git a/Pod/UIKit/Classes/UITextField+BonMotUtilities.h b/Pod/UIKit/Classes/UITextField+BonMotUtilities.h index b9bcb896..51fadfc4 100644 --- a/Pod/UIKit/Classes/UITextField+BonMotUtilities.h +++ b/Pod/UIKit/Classes/UITextField+BonMotUtilities.h @@ -3,7 +3,7 @@ // BonMot // // Created by Nora Trapp on 3/2/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // @import UIKit; diff --git a/Pod/UIKit/Classes/UITextField+BonMotUtilities.m b/Pod/UIKit/Classes/UITextField+BonMotUtilities.m index 94e88e68..b2a23143 100644 --- a/Pod/UIKit/Classes/UITextField+BonMotUtilities.m +++ b/Pod/UIKit/Classes/UITextField+BonMotUtilities.m @@ -3,7 +3,7 @@ // BonMot // // Created by Nora Trapp on 3/2/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // #import "BonMot.h" diff --git a/Pod/UIKit/Classes/UITextView+BonMotUtilities.h b/Pod/UIKit/Classes/UITextView+BonMotUtilities.h index ddcce300..9578df3e 100644 --- a/Pod/UIKit/Classes/UITextView+BonMotUtilities.h +++ b/Pod/UIKit/Classes/UITextView+BonMotUtilities.h @@ -3,7 +3,7 @@ // BonMot // // Created by Nora Trapp on 3/2/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // @import UIKit; diff --git a/Pod/UIKit/Classes/UITextView+BonMotUtilities.m b/Pod/UIKit/Classes/UITextView+BonMotUtilities.m index 17531209..128f31ad 100644 --- a/Pod/UIKit/Classes/UITextView+BonMotUtilities.m +++ b/Pod/UIKit/Classes/UITextView+BonMotUtilities.m @@ -3,7 +3,7 @@ // BonMot // // Created by Nora Trapp on 3/2/16. -// +// Copyright © 2015 Zev Eisenberg. All rights reserved. // #import "BonMot.h" diff --git a/README.md b/README.md index a469a756..ebc03697 100644 --- a/README.md +++ b/README.md @@ -270,15 +270,15 @@ Prints this: ## Tag Styles -BonMot can style text between arbirtrary tags using a `` format and `\` as an escape character. +BonMot can style text between arbirtrary tags using a `` format and `\` as an escape character. This allows you to apply styles to substrings of localized strings, whose position, order, and even existence may change from language to language. ```objc BONChain *boldChain = BONChain.new.fontNameAndSize(@"Baskerville-Bold", 15.0f); BONChain *italicChain = BONChain.new.fontNameAndSize(@"Baskerville-Italic", 15.0f); BONChain *chain = BONChain.new.fontNameAndSize(@"Baskerville", 17.0f) - .tagStyles(@[BONTagMake(@"bold", boldChain), BONTagMake(@"italic", italicChain)]) - .string(@"This text is wrapped in a \\ tag.\nThis text is wrapped in an \\ tag."); + .tagStyles( @{ @"bold": boldChain, @"italic": italicChain } ) + .string(@"This text contains a \\ tag.\nThis text contains an \\ tag."); NSAttributedString *string = chain.attributedString; ``` @@ -294,7 +294,7 @@ BONChain *boldChain = BONChain.new.fontNameAndSize(@"Baskerville-Bold", 15.0f); BONChain *italicChain = BONChain.new.fontNameAndSize(@"Baskerville-Italic", 15.0f); BONChain *chain = BONChain.new.fontNameAndSize(@"Baskerville", 17.0f) -.tagStyles(@[BONTagComplexMake(@"~start~", @"!end", @"escape", boldChain)]) +.tagComplexStyles(@[BONTagComplexMake(@"~start~", @"!end", @"escape", boldChain)]) .string(@"~start~This text is wrapped in a escape~start~ tag.!end"); NSAttributedString *string = chain.attributedString; diff --git a/readme-images/tag-styling.png b/readme-images/tag-styling.png index 64900b6e..56eb475c 100644 Binary files a/readme-images/tag-styling.png and b/readme-images/tag-styling.png differ