-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,24 @@ | |
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
// final class => public | ||
public class StringBuilder { | ||
|
||
var content : String = "" | ||
var content : String = "" // TODO: implements direct a char array | ||
|
||
/// Default constructor | ||
public init (){} | ||
|
||
public init (_ newContent : String) { | ||
self.content = newContent | ||
} | ||
|
||
// TODO: Test it | ||
public init (_ newContent : any CharSequence) { | ||
self.content = "\(newContent)" | ||
} | ||
|
||
/// Append a String type | ||
/// - Parameters String to append | ||
/// - Returns self (fluent interface pattern) | ||
|
@@ -27,6 +38,15 @@ public class StringBuilder { | |
return self | ||
} | ||
|
||
public func deleteAt (_ offset : Int) throws -> StringBuilder { | ||
guard offset > -1, offset < self.count else { | ||
throw java.lang.Throwable.IndexOutOufBoundsException(offset, "the index is negative or greater than or equal to count of String") | ||
} | ||
var asCharArray = Array(self.content) | ||
asCharArray.removeFirst(offset) | ||
return StringBuilder(String(asCharArray)) | ||
} | ||
|
||
public func length () -> Int { | ||
return content.lenght() | ||
} | ||
|