Skip to content

Commit

Permalink
feat: Added VTSingleLineString
Browse files Browse the repository at this point in the history
  • Loading branch information
macmade committed Mar 19, 2024
1 parent 40d9e4b commit 0f792fb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ValueTransformers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
05233032243CD25B005BBB8E /* ValueTransformers.h in Headers */ = {isa = PBXBuildFile; fileRef = 05233031243CD25B005BBB8E /* ValueTransformers.h */; settings = {ATTRIBUTES = (Public, ); }; };
05233035243CD294005BBB8E /* PerformSelectorUnsafe.h in Headers */ = {isa = PBXBuildFile; fileRef = 05233033243CD294005BBB8E /* PerformSelectorUnsafe.h */; settings = {ATTRIBUTES = (Public, ); }; };
05233036243CD294005BBB8E /* PerformSelectorUnsafe.m in Sources */ = {isa = PBXBuildFile; fileRef = 05233034243CD294005BBB8E /* PerformSelectorUnsafe.m */; };
058AC6302BA9E1AD001EEB04 /* SingleLineString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 058AC62F2BA9E1AD001EEB04 /* SingleLineString.swift */; };
05D3735E20ED91E5007FE14A /* StringIsNotEmpty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D3734320ED91E5007FE14A /* StringIsNotEmpty.swift */; };
05D3735F20ED91E5007FE14A /* ArrayIsEmpty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D3734420ED91E5007FE14A /* ArrayIsEmpty.swift */; };
05D3736020ED91E5007FE14A /* StringIsEmpty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D3734520ED91E5007FE14A /* StringIsEmpty.swift */; };
Expand Down Expand Up @@ -84,6 +85,7 @@
05233031243CD25B005BBB8E /* ValueTransformers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ValueTransformers.h; sourceTree = "<group>"; };
05233033243CD294005BBB8E /* PerformSelectorUnsafe.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PerformSelectorUnsafe.h; sourceTree = "<group>"; };
05233034243CD294005BBB8E /* PerformSelectorUnsafe.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PerformSelectorUnsafe.m; sourceTree = "<group>"; };
058AC62F2BA9E1AD001EEB04 /* SingleLineString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleLineString.swift; sourceTree = "<group>"; };
05A6D085238BF1700032EA48 /* Debug - Library.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Debug - Library.xcconfig"; sourceTree = "<group>"; };
05A6D086238BF1700032EA48 /* Release - Library.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Release - Library.xcconfig"; sourceTree = "<group>"; };
05CD4AB220ED7B2200DBDE99 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -270,6 +272,7 @@
05233034243CD294005BBB8E /* PerformSelectorUnsafe.m */,
EF0F53582715DB6100BE981A /* SetIsEmpty.swift */,
EF0F535A2715DD1900BE981A /* SetIsNotEmpty.swift */,
058AC62F2BA9E1AD001EEB04 /* SingleLineString.swift */,
05D3734520ED91E5007FE14A /* StringIsEmpty.swift */,
05D3734320ED91E5007FE14A /* StringIsNotEmpty.swift */,
05D3734E20ED91E5007FE14A /* UppercaseString.swift */,
Expand Down Expand Up @@ -427,6 +430,7 @@
05D3736920ED91E5007FE14A /* UppercaseString.swift in Sources */,
05D3736620ED91E5007FE14A /* BoolToDisabledTextColor.swift in Sources */,
05233036243CD294005BBB8E /* PerformSelectorUnsafe.m in Sources */,
058AC6302BA9E1AD001EEB04 /* SingleLineString.swift in Sources */,
05D3735E20ED91E5007FE14A /* StringIsNotEmpty.swift in Sources */,
05D3736720ED91E5007FE14A /* ArrayIsNotEmpty.swift in Sources */,
05D3736220ED91E5007FE14A /* NumberIsGreaterThanZero.swift in Sources */,
Expand Down
47 changes: 47 additions & 0 deletions ValueTransformers/SingleLineString.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2022, Jean-David Gadina - www.xs-labs.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/

import Foundation

@objc( VTSingleLineString )
public class SingleLineString: ValueTransformer
{
@objc
public override class func transformedValueClass() -> AnyClass
{
return NSString.self
}

@objc
public override class func allowsReverseTransformation() -> Bool
{
return false
}

@objc
public override func transformedValue( _ value: Any? ) -> Any?
{
( value as? String )?.components( separatedBy: .newlines ).first
}
}
15 changes: 15 additions & 0 deletions ValueTransformersTests/ValueTransformersTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,19 @@ - ( void )testVTSetIsNotEmpty
XCTAssertTrue( ( ( NSNumber * )[ vt transformedValue: [ NSSet setWithArray: @[ @"" ] ] ] ).boolValue, @"" );
}

- ( void )testSingleLineString
{
VTSingleLineString * vt;

vt = [ VTSingleLineString new ];

XCTAssertEqual( [ VTSingleLineString transformedValueClass ], [ NSString class ], @"" );
XCTAssertFalse( [ VTSingleLineString allowsReverseTransformation ], @"" );

XCTAssertEqualObjects( [ vt transformedValue: nil ], nil, @"" );
XCTAssertEqualObjects( [ vt transformedValue: @0 ], nil, @"" );
XCTAssertEqualObjects( [ vt transformedValue: @"hello, world" ], @"hello, world", @"" );
XCTAssertEqualObjects( [ vt transformedValue: @"hello, world\nhello, universe" ], @"hello, world", @"" );
}

@end

0 comments on commit 0f792fb

Please sign in to comment.