Added documentation. Light cleanup.

This commit is contained in:
Kare Morstol
2014-08-26 00:24:26 +02:00
parent d39a3c8d58
commit 10f623d4c8
3 changed files with 26 additions and 9 deletions
+20 -3
View File
@@ -8,23 +8,40 @@
import Foundation
// TODO: get encoding from environmental variable LC_TYPE
public var streamencoding = NSUTF8StringEncoding
/** A stream of text. Does as much as possible lazily. */
public protocol ReadableStreamType : Streamable {
/**
Whatever amount of text the stream feels like providing.
If the source is a file this will read everything at once.
:returns: more text from the stream, or nil if we have reached the end.
*/
func readSome() -> String?
/// Reads everything at once.
func read() -> String
func lines() -> SequenceOf <String >
/// Lazily splits the stream into lines
func lines() -> SequenceOf<String>
/// Allows stream to be used by "println"
func writeTo<Target : OutputStreamType>(inout target: Target)
}
/** An output stream, like standard output and standard error. */
public protocol WriteableStreamType : OutputStreamType {
func write(string: String)
/// Must be called on local streams when done writing.
func closeStream()
}
/** Creates a stream from a String. */
public func stream(text: String) -> ReadableStreamType {
let pipe = NSPipe()
let input = pipe.fileHandleForWriting
@@ -79,7 +96,7 @@ struct StringStreamGenerator : GeneratorType {
return nextline
} else {
if let newcache = stream.readSome() {
cache = nextline + newcache // TODO: crashes on long streams
cache = nextline + newcache
return next()
} else {
return nextline == "" ? nil : nextline
@@ -109,7 +109,7 @@ class Stream_Iteration_SpeedTests: XCTestCase {
func allSpeedIterateOverFile() -> Array<UInt64>{
let longtextpath = pathForTestResource("long text", type: "txt")
var times = Array<UInt64>(count: numberoflines, repeatedValue: 0)
var times = Array<UInt64>(count: numberoflines, repeatedValue: 0)
let f = open(longtextpath)
let start = mach_absolute_time()
+5 -5
View File
@@ -1,10 +1,10 @@
#!/bin/bash
# swiftshell.bash
# SwiftShell
# swiftshell.bash
# SwiftShell
#
# Created by Kåre Morstøl on 24/08/14.
# Copyright (c) 2014 NotTooBad Software. All rights reserved.
# Created by Kåre Morstøl on 24/08/14.
# Copyright (c) 2014 NotTooBad Software. All rights reserved.
# The folders where Swift can find the frameworks it imports as modules.
# SwiftShell.framework must be in one of these.
@@ -13,7 +13,7 @@ FRAMEWORKS_PATH=$DYLD_FRAMEWORK_PATH:~/Library/Frameworks:/Library/Frameworks
# Add a : to the beginning if not already there
if [[ $FRAMEWORKS_PATH != :* ]]
then
FRAMEWORKS_PATH=:$FRAMEWORKS_PATH
FRAMEWORKS_PATH=:$FRAMEWORKS_PATH
fi
# Swift needs folders one at a time, so we replace : with " -F "