Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dileping committed Jul 26, 2016
2 parents c3e2838 + 5b967b4 commit 8e4b5da
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
2 changes: 2 additions & 0 deletions Markdown.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -328,6 +329,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
6 changes: 2 additions & 4 deletions Markdown/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
//
//===----------------------------------------------------------------------===//

import Foundation

public enum Error : ErrorType {
public enum Error : ErrorProtocol {
case Compile(code:Int32)
case Produce(code:Int32)
}
}
2 changes: 1 addition & 1 deletion Markdown/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<string>1.0.0-alpha.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
24 changes: 12 additions & 12 deletions Markdown/Markdown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import CDiscount

private typealias PMMIOT = UnsafeMutablePointer<Void>
private typealias MKDFUN = (PMMIOT, UnsafeMutablePointer<UnsafeMutablePointer<Int8>>) -> Int32
private typealias MKDFUN = (PMMIOT, UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>) -> Int32

public class Markdown {
private let _markdown:PMMIOT
Expand All @@ -43,8 +43,8 @@ public class Markdown {
try self.init(markdown: mkd_string(string, Int32(string.characters.count), 0), options: options)
}

private func data(fun:MKDFUN, deallocator:UnsafeMutablePointer<Int8>->Void) throws -> String {
var dest = [UnsafeMutablePointer<Int8>](count: 1, repeatedValue: UnsafeMutablePointer<Int8>.alloc(1))
private func data(with fun:MKDFUN, deallocator:(UnsafeMutablePointer<Int8>?)->Void) throws -> String {
var dest = [UnsafeMutablePointer<Int8>?](repeating: UnsafeMutablePointer<Int8>(allocatingCapacity: 1), count: 1)

let result = fun(_markdown, &dest)
defer {
Expand All @@ -56,43 +56,43 @@ public class Markdown {
throw Error.Produce(code: result)
}

guard let string = String.fromCString(dest[0]) else {
guard let data = dest[0] else {
return ""
}

return string
return String(cString: data)
}

public func document() throws -> String {
return try data(mkd_document) { pointer in
return try data(with: mkd_document) { pointer in
}
}

public func css() throws -> String {
return try data(mkd_css) { pointer in
return try data(with: mkd_css) { pointer in
}
}

public func tableOfContents() throws -> String {
return try data(mkd_toc) { pointer in
return try data(with: mkd_toc) { pointer in
}
}

public var title:String? {
get {
return String.fromCString(mkd_doc_title(_markdown))
return String(cString: mkd_doc_title(_markdown))
}
}

public var author:String? {
get {
return String.fromCString(mkd_doc_author(_markdown))
return String(cString: mkd_doc_author(_markdown))
}
}

public var date:String? {
get {
return String.fromCString(mkd_doc_date(_markdown))
return String(cString: mkd_doc_date(_markdown))
}
}
}
}
4 changes: 2 additions & 2 deletions Markdown/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import Foundation
import CDiscount

public struct Options : OptionSetType {
public struct Options : OptionSet {
public let rawValue: UInt32

public init(rawValue: UInt32) {
Expand Down Expand Up @@ -64,4 +64,4 @@ public struct Options : OptionSetType {
// public static let UrlEncodedAnchor = Options(rawValue: UInt32(MKD_URLENCODEDANCHOR))

public static let Embed:Options = [.NoLinks, .NoImage, .TagText]
}
}
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ let package = Package(
name: "Markdown"
),
],
dependencies: [.Package(url: "https://github.com/crossroadlabs/CDiscount.git", majorVersion: 0)]
dependencies: [.Package(url: "https://github.com/crossroadlabs/CDiscount.git", majorVersion: 0)],
exclude: ["Carthage"]
)
14 changes: 8 additions & 6 deletions Tests/Markdown/MarkdownTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
//===----------------------------------------------------------------------===//

import XCTest
import Foundation

@testable import Markdown

#if !os(Linux) || dispatch
Expand Down Expand Up @@ -85,12 +87,12 @@ class MarkdownTests: XCTestCase {
#if !os(Linux) || dispatch
// no dispatch
func testStress() {
let id = NSUUID().UUIDString
let queue = dispatch_queue_create(id, DISPATCH_QUEUE_CONCURRENT)
let id = UUID().uuidString
let queue = DispatchQueue(label: id, attributes: DispatchQueueAttributes.concurrent)

for i in 0...10000 {
let expectation = self.expectationWithDescription("OK " + String(i))
dispatch_async(queue) {
let expectation = self.expectation(description: "OK " + String(i))
queue.async {
do {
let markdown = try Markdown(string: "# test line " + String(i), options: .None)
let html = try markdown.document()
Expand All @@ -103,7 +105,7 @@ class MarkdownTests: XCTestCase {
}
}

self.waitForExpectationsWithTimeout(30, handler: nil)
self.waitForExpectations(timeout: 30, handler: nil)
}

#endif
Expand All @@ -127,4 +129,4 @@ extension MarkdownTests : XCTestCaseProvider {
return tests
}
}
#endif
#endif

0 comments on commit 8e4b5da

Please sign in to comment.