Make sprintf no longer global, instead ObjectiveJ.sprintf.

This commit is contained in:
Ross Boucher
2010-03-07 17:41:33 -08:00
parent c3ac076d13
commit e3dc9fd96b
7 changed files with 15 additions and 14 deletions
+1 -1
View File
@@ -238,7 +238,7 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
total++;
totalBytes += aFileExecutable.code().length
}, this);
stream.print(sprintf(
stream.print(ObjectiveJ.sprintf(
"Saved \0green(%f%%\0) (\0blue(%s\0)); Total required files: \0magenta(%d\0) (\0blue(%s\0)) of \0magenta(%d\0) (\0blue(%s\0));",
Math.round(((includedBytes - totalBytes) / totalBytes) * -100),
bytesToString(totalBytes - includedBytes),
+3 -3
View File
@@ -142,7 +142,7 @@ var CPStringRegexSpecialCharacters = [
[CPException raise:CPInvalidArgumentException
reason:"initWithFormat: the format can't be 'nil'"];
self = sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
self = ObjectiveJ.sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
return self;
}
@@ -158,7 +158,7 @@ var CPStringRegexSpecialCharacters = [
[CPException raise:CPInvalidArgumentException
reason:"initWithFormat: the format can't be 'nil'"];
return sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
return ObjectiveJ.sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
}
/*!
@@ -199,7 +199,7 @@ var CPStringRegexSpecialCharacters = [
if (!format)
[CPException raise:CPInvalidArgumentException reason:"initWithFormat: the format can't be 'nil'"];
return self + sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
return self + ObjectiveJ.sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
}
/*!
+3 -3
View File
@@ -82,7 +82,7 @@ function _CPLogDispatch(parameters, aLevel, aTitle)
aLevel = CPLogDefaultLevel;
// use sprintf if param 0 is a string and there is more than one param. otherwise just convert param 0 to a string
var message = (typeof parameters[0] == "string" && parameters.length > 1) ? sprintf.apply(null, parameters) : String(parameters[0]);
var message = (typeof parameters[0] == "string" && parameters.length > 1) ? exports.sprintf.apply(null, parameters) : String(parameters[0]);
if (_CPLogRegistrations[aLevel])
for (var i = 0; i < _CPLogRegistrations[aLevel].length; i++)
@@ -103,8 +103,8 @@ var _CPFormatLogMessage = function(aString, aLevel, aTitle)
var now = new Date();
aLevel = ( aLevel == null ? '' : ' [' + aLevel + ']' );
if (typeof sprintf == "function")
return sprintf("%4d-%02d-%02d %02d:%02d:%02d.%03d %s%s: %s",
if (typeof exports.sprintf == "function")
return exports.sprintf("%4d-%02d-%02d %02d:%02d:%02d.%03d %s%s: %s",
now.getFullYear(), now.getMonth(), now.getDate(),
now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds(),
aTitle, aLevel, aString);
@@ -1,14 +1,14 @@
var objj = null;
function ObjectiveJLoader() {
var loader = {};
var factories = {};
loader.reload = function(topId, path) {
if (!objj) objj = require("objective-j");
if (!global.ObjectiveJ)
global.ObjectiveJ = require("objective-j");
//print("loading objective-j: " + topId + " (" + path + ")");
factories[topId] = objj.make_narwhal_factory(path);
factories[topId] = ObjectiveJ.make_narwhal_factory(path);
factories[topId].path = path;
}
+2 -2
View File
@@ -24,12 +24,12 @@
function objj_debug_object_format(aReceiver)
{
return (aReceiver && aReceiver.isa) ? sprintf("<%s %#08x>", GETMETA(aReceiver).name, aReceiver._UID) : String(aReceiver);
return (aReceiver && aReceiver.isa) ? exports.sprintf("<%s %#08x>", GETMETA(aReceiver).name, aReceiver._UID) : String(aReceiver);
}
function objj_debug_message_format(aReceiver, aSelector)
{
return sprintf("[%s %s]", objj_debug_object_format(aReceiver), aSelector);
return exports.sprintf("[%s %s]", objj_debug_object_format(aReceiver), aSelector);
}
+1 -1
View File
@@ -25,7 +25,7 @@
var formatRegex = new RegExp("([^%]+|%[\\+\\-\\ \\#0]*[0-9\\*]*(.[0-9\\*]+)?[hlL]?[cbBdieEfgGosuxXpn%@])", "g");
var tagRegex = new RegExp("(%)([\\+\\-\\ \\#0]*)([0-9\\*]*)((.[0-9\\*]+)?)([hlL]?)([cbBdieEfgGosuxXpn%@])");
GLOBAL(sprintf) = function(format)
exports.sprintf = function(format)
{
var format = arguments[0],
tokens = format.match(formatRegex),
+2 -1
View File
@@ -1,3 +1,4 @@
// TODO: add many many more of these...
var sprintfTestCases = [
[["[%@]", "hello world"], "[hello world]"],
@@ -12,7 +13,7 @@ var sprintfTestCases = [
{
for (var i = 0; i < sprintfTestCases.length; i++)
{
[self assert:sprintf.apply(null, sprintfTestCases[i][0]) equals:sprintfTestCases[i][1]];
[self assert:ObjectiveJ.sprintf.apply(null, sprintfTestCases[i][0]) equals:sprintfTestCases[i][1]];
}
}