Bug 1264696 - Part 1: Move string utility functions to rep-utils. r=Honza
--- a/devtools/client/shared/components/reps/function.js
+++ b/devtools/client/shared/components/reps/function.js
@@ -6,19 +6,18 @@
"use strict";
// Make this available to both AMD and CJS environments
define(function (require, exports, module) {
// ReactJS
const React = require("devtools/client/shared/vendor/react");
// Reps
- const { createFactories, isGrip } = require("./rep-utils");
+ const { createFactories, isGrip, cropString } = require("./rep-utils");
const { ObjectLink } = createFactories(require("./object-link"));
- const { cropString } = require("./string");
/**
* This component represents a template for Function objects.
*/
let Func = React.createClass({
displayName: "Func",
propTypes: {
--- a/devtools/client/shared/components/reps/rep-utils.js
+++ b/devtools/client/shared/components/reps/rep-utils.js
@@ -26,12 +26,57 @@ define(function (require, exports, modul
/**
* Returns true if the given object is a grip (see RDP protocol)
*/
function isGrip(object) {
return object && object.actor;
}
+
+ function escapeNewLines(value) {
+ return value.replace(/\r/gm, "\\r").replace(/\n/gm, "\\n");
+ }
+
+ function cropMultipleLines(text, limit) {
+ return escapeNewLines(cropString(text, limit));
+ }
+
+ function cropString(text, limit, alternativeText) {
+ if (!alternativeText) {
+ alternativeText = "\u2026";
+ }
+
+ // Make sure it's a string.
+ text = text + "";
+
+ // Use default limit if necessary.
+ if (!limit) {
+ limit = 50;
+ }
+
+ // Crop the string only if a limit is actually specified.
+ if (limit <= 0) {
+ return text;
+ }
+
+ // Set the limit at least to the length of the alternative text
+ // plus one character of the original text.
+ if (limit <= alternativeText.length) {
+ limit = alternativeText.length + 1;
+ }
+
+ let halfLimit = (limit - alternativeText.length) / 2;
+
+ if (text.length > limit) {
+ return text.substr(0, Math.ceil(halfLimit)) + alternativeText +
+ text.substr(text.length - Math.floor(halfLimit));
+ }
+
+ return text;
+ }
+
// Exports from this module
exports.createFactories = createFactories;
exports.isGrip = isGrip;
+ exports.cropString = cropString;
+ exports.cropMultipleLines = cropMultipleLines;
});
--- a/devtools/client/shared/components/reps/string.js
+++ b/devtools/client/shared/components/reps/string.js
@@ -5,17 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// Make this available to both AMD and CJS environments
define(function (require, exports, module) {
// Dependencies
const React = require("devtools/client/shared/vendor/react");
- const { createFactories } = require("./rep-utils");
+ const { createFactories, cropMultipleLines } = require("./rep-utils");
const { ObjectBox } = createFactories(require("./object-box"));
/**
* Renders a string. String value is enclosed within quotes.
*/
const StringRep = React.createClass({
displayName: "StringRep",
@@ -35,70 +35,19 @@ define(function (require, exports, modul
"\"" + cropMultipleLines(text) + "\""
)
);
},
});
// Helpers
- function escapeNewLines(value) {
- return value.replace(/\r/gm, "\\r").replace(/\n/gm, "\\n");
- }
-
- function cropMultipleLines(text, limit) {
- return escapeNewLines(cropString(text, limit));
- }
-
- function cropString(text, limit, alternativeText) {
- if (!alternativeText) {
- alternativeText = "\u2026";
- }
-
- // Make sure it's a string.
- text = text + "";
-
- // Use default limit if necessary.
- if (!limit) {
- limit = 50;
- }
-
- // Crop the string only if a limit is actually specified.
- if (limit <= 0) {
- return text;
- }
-
- // Set the limit at least to the length of the alternative text
- // plus one character of the original text.
- if (limit <= alternativeText.length) {
- limit = alternativeText.length + 1;
- }
-
- let halfLimit = (limit - alternativeText.length) / 2;
-
- if (text.length > limit) {
- return text.substr(0, Math.ceil(halfLimit)) + alternativeText +
- text.substr(text.length - Math.floor(halfLimit));
- }
-
- return text;
- }
-
- function isCropped(value) {
- let cropLength = 50;
- return typeof value == "string" && value.length > cropLength;
- }
-
function supportsObject(object, type) {
return (type == "string");
}
// Exports from this module
exports.StringRep = {
rep: StringRep,
supportsObject: supportsObject,
};
-
- exports.isCropped = isCropped;
- exports.cropString = cropString;
- exports.cropMultipleLines = cropMultipleLines;
});
--- a/devtools/client/shared/components/reps/text-node.js
+++ b/devtools/client/shared/components/reps/text-node.js
@@ -6,19 +6,18 @@
"use strict";
// Make this available to both AMD and CJS environments
define(function (require, exports, module) {
// ReactJS
const React = require("devtools/client/shared/vendor/react");
// Reps
- const { createFactories, isGrip } = require("./rep-utils");
+ const { createFactories, isGrip, cropMultipleLines } = require("./rep-utils");
const { ObjectLink } = createFactories(require("./object-link"));
- const { cropMultipleLines } = require("./string");
// Shortcuts
const DOM = React.DOM;
/**
* Renders DOM #text node.
*/
let TextNode = React.createClass({
--- a/devtools/client/shared/components/reps/window.js
+++ b/devtools/client/shared/components/reps/window.js
@@ -6,19 +6,18 @@
"use strict";
// Make this available to both AMD and CJS environments
define(function (require, exports, module) {
// ReactJS
const React = require("devtools/client/shared/vendor/react");
// Reps
- const { createFactories, isGrip } = require("./rep-utils");
+ const { createFactories, isGrip, cropString } = require("./rep-utils");
const { ObjectBox } = createFactories(require("./object-box"));
- const { cropString } = require("./string");
// Shortcuts
const DOM = React.DOM;
/**
* Renders a grip representing a window.
*/
let Window = React.createClass({