Skip to content

Commit

Permalink
Merge pull request #13 from coshx/fix/strings_starting_with_number
Browse files Browse the repository at this point in the history
Fixes string casting
  • Loading branch information
acadet committed Nov 8, 2015
2 parents f0bf1d3 + b3d0c59 commit 1fc5ae6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Caravel.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
# summary should be tweet-length, and the description more in depth.
#

version = "0.4.2"
version = "0.4.3"

s.name = "Caravel"
s.version = version
Expand Down
10 changes: 10 additions & 0 deletions caravel-test/EventDataController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public class EventDataController: UIViewController {
}
}

bus.register("UUID") { name, data in
if let s = data as? String {
if s != "9658ae60-9e0d-4da7-a63d-46fe75ff1db1" {
self._raise("UUID - bad value")
}
} else {
self._raise("UUID - bad type")
}
}

bus.register("Array") { name, data in
if let a = data as? NSArray {
if a.count != 3 {
Expand Down
1 change: 1 addition & 0 deletions caravel-test/js/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Caravel.getDefault().post("Int", 987);
Caravel.getDefault().post("Float", 19.89);
Caravel.getDefault().post("Double", 15.15);
Caravel.getDefault().post("String", "Napoleon");
Caravel.getDefault().post("UUID", "9658ae60-9e0d-4da7-a63d-46fe75ff1db1");
Caravel.getDefault().post("Array", [3, 1, 4]);
Caravel.getDefault().post("Dictionary", { "movie": "Once upon a time in the West", "actor": "Charles Bronson" });

Expand Down
6 changes: 3 additions & 3 deletions caravel/ArgumentParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ internal class ArgumentParser {
for p in queryPairs {
var keyValue = p.componentsSeparatedByString("=")
if keyValue[0] == "busName" {
outcome.busName = keyValue[1].stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
outcome.busName = keyValue[1].stringByRemovingPercentEncoding!
} else if keyValue[0] == "eventName" {
outcome.eventName = keyValue[1].stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
outcome.eventName = keyValue[1].stringByRemovingPercentEncoding!
} else if keyValue[0] == "eventData" {
outcome.eventData = keyValue[1].stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
outcome.eventData = keyValue[1].stringByRemovingPercentEncoding
}
}

Expand Down
14 changes: 11 additions & 3 deletions caravel/DataSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,17 @@ internal class DataSerializer {
return try! NSJSONSerialization.JSONObjectWithData(json, options: NSJSONReadingOptions())
}

// To investigate if the input is a number (int or double),
// we check if the first char is a digit or no
if let _ = Int(input[0]) {
var isNumber = true
for i in 0..<input.characters.count {
if Int(input[i]) != nil || input[i] == "." || input[i] == "," {
// Do nothing
} else {
isNumber = false
break
}
}

if isNumber {
if let i = Int(input) {
return i
} else {
Expand Down
2 changes: 1 addition & 1 deletion caravel/js/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function (grunt) {
'use strict';

var version = '0.4.2';
var version = '0.4.3';

// Project configuration
grunt.initConfig({
Expand Down
2 changes: 1 addition & 1 deletion caravel/js/caravel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1fc5ae6

Please sign in to comment.