mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
Make sprintf no longer global, instead ObjectiveJ.sprintf.
This commit is contained in:
+1
-1
@@ -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),
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user