https://github.com/chris-huxtable/cbhstringsplitter
A convenient utility for splitting stings with a minimal memory footprint.
https://github.com/chris-huxtable/cbhstringsplitter
objective-c objective-c-library
Last synced: 25 days ago
JSON representation
A convenient utility for splitting stings with a minimal memory footprint.
- Host: GitHub
- URL: https://github.com/chris-huxtable/cbhstringsplitter
- Owner: chris-huxtable
- License: isc
- Created: 2019-11-02T22:17:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-22T01:29:00.000Z (over 5 years ago)
- Last Synced: 2025-03-10T07:35:40.114Z (about 2 months ago)
- Topics: objective-c, objective-c-library
- Language: Objective-C
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CBHStringSplitter
[](https://github.com/chris-huxtable/CBHStringSplitter/releases)
[](https://cocoapods.org/pods/CBHStringSplitter)
[](https://github.com/chris-huxtable/CBHStringSplitter/blob/master/LICENSE)
[](https://github.com/chris-huxtable/CBHStringSplitter)`CBHStringSplitter` is an `NSEnumerator` subclass which splits strings using an `NSInputStream` to process input with minimal memory use.
While `CBHStringSplitter` is slightly slower than the equivalent `componentsSeparatedByCharactersInSet` it does not load the entire contents of a file into memory. This makes it more appropriate for some use cases.
## Examples
### Process each line in a file using a for in loop:
```objective-c
NSString *path = @"/path/to/file";
CBHStringSplitter *splitter = [CBHStringSplitter splitterWithFileAtPath:path andSeparators:[NSCharacterSet newlineCharacterSet]];for (NSString *line in splitter)
{
// Do something with the line...
}
```### Process each line in a file using a while loop:
```objective-c
NSString *path = @"/path/to/file";
CBHStringSplitter *splitter = [CBHStringSplitter splitterWithFileAtPath:path andSeparators:[NSCharacterSet newlineCharacterSet]];NSString *line;
while ( (line = [splitter nextObject]) )
{
// Do something with the line...
}
```## Notes:
- Unlike `componentsSeparatedByCharactersInSet` if the input is suffixed with a separator character an empty string will not be given as the last entry. It will just be ignored.
## TODO:
- Performance Improvements
- Simplify buffering
- Block based enumerationPull requests are welcome.
## Licence
CBHStringSplitter is available under the [ISC license](https://github.com/chris-huxtable/CBHStringSplitter/blob/master/LICENSE).