Remove goog.string

This commit is contained in:
Neil Fraser
2018-06-10 21:28:29 -07:00
committed by Neil Fraser
parent 3909bd420a
commit 03bf9f5e71
7 changed files with 35 additions and 19 deletions

View File

@@ -41,7 +41,6 @@ goog.require('Blockly.Workspace');
goog.require('Blockly.Xml');
goog.require('goog.array');
goog.require('goog.math.Coordinate');
goog.require('goog.string');
/**
@@ -1055,12 +1054,14 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) {
}
}
}
text = goog.string.trim(text.join(' ')) || '???';
text = text.join(' ').trim() || '???';
if (opt_maxLength) {
// TODO: Improve truncation so that text from this block is given priority.
// E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not "1+2+3+4+5...".
// E.g. "1+2+3+4+5=6+7+8+9+0" should be "...4+5=6+7...".
text = goog.string.truncate(text, opt_maxLength);
if (text.length > opt_maxLength) {
text = text.substring(0, opt_maxLength - 3) + '...';
}
}
return text;
};
@@ -1260,7 +1261,7 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
}
// Add last dummy input if needed.
if (elements.length && (typeof elements[elements.length - 1] == 'string' ||
goog.string.startsWith(
Blockly.utils.startsWith(
elements[elements.length - 1]['type'], 'field_'))) {
var dummyInput = {type: 'input_dummy'};
if (lastDummyAlign) {

View File

@@ -30,7 +30,6 @@ goog.require('Blockly.FieldDropdown');
goog.require('Blockly.Msg');
goog.require('Blockly.VariableModel');
goog.require('Blockly.Variables');
goog.require('goog.string');
/**

View File

@@ -505,8 +505,9 @@ Blockly.Gesture.prototype.doStart = function(e) {
return;
}
if (goog.string.caseInsensitiveEquals(e.type, 'touchstart') ||
(goog.string.caseInsensitiveEquals(e.type, 'pointerdown') && e.pointerType != 'mouse')) {
if ((e.type.toLowerCase() == 'touchstart' ||
e.type.toLowerCase() == 'pointerdown') &&
e.pointerType != 'mouse') {
Blockly.longStart_(e, this);
}

View File

@@ -32,7 +32,6 @@ goog.provide('Blockly.Touch');
goog.require('goog.events');
goog.require('goog.events.BrowserFeature');
goog.require('goog.string');
/**
@@ -198,7 +197,7 @@ Blockly.Touch.checkTouchIdentifier = function(e) {
* @param {!Event} e A touch event.
*/
Blockly.Touch.setClientFromTouch = function(e) {
if (goog.string.startsWith(e.type, 'touch')) {
if (Blockly.utils.startsWith(e.type, 'touch')) {
// Map the touch event's properties to the event.
var touchPoint = e.changedTouches[0];
e.clientX = touchPoint.clientX;
@@ -212,9 +211,9 @@ Blockly.Touch.setClientFromTouch = function(e) {
* @return {boolean} true if it is a mouse or touch event; false otherwise.
*/
Blockly.Touch.isMouseOrTouchEvent = function(e) {
return goog.string.startsWith(e.type, 'touch') ||
goog.string.startsWith(e.type, 'mouse') ||
goog.string.startsWith(e.type, 'pointer');
return Blockly.utils.startsWith(e.type, 'touch') ||
Blockly.utils.startsWith(e.type, 'mouse') ||
Blockly.utils.startsWith(e.type, 'pointer');
};
/**
@@ -223,8 +222,8 @@ Blockly.Touch.isMouseOrTouchEvent = function(e) {
* @return {boolean} true if it is a touch event; false otherwise.
*/
Blockly.Touch.isTouchEvent = function(e) {
return goog.string.startsWith(e.type, 'touch') ||
goog.string.startsWith(e.type, 'pointer');
return Blockly.utils.startsWith(e.type, 'touch') ||
Blockly.utils.startsWith(e.type, 'pointer');
};
/**

View File

@@ -525,7 +525,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message,
// BKY_ is the prefix used to namespace the strings used in Blockly
// core files and the predefined blocks in ../blocks/. These strings
// are defined in ../msgs/ files.
var bklyKey = goog.string.startsWith(keyUpper, 'BKY_') ?
var bklyKey = Blockly.utils.startsWith(keyUpper, 'BKY_') ?
keyUpper.substring(4) : null;
if (bklyKey && bklyKey in Blockly.Msg) {
var rawValue = Blockly.Msg[bklyKey];
@@ -901,3 +901,14 @@ Blockly.utils.getViewportBBox = function() {
left: scrollOffset.x
};
};
/**
* Fast prefix-checker.
* Copied from Closure's goog.string.startsWith.
* @param {string} str The string to check.
* @param {string} prefix A string to look for at the start of `str`.
* @return {boolean} True if `str` begins with `prefix`.
*/
Blockly.utils.startsWith = function(str, prefix) {
return str.lastIndexOf(prefix, 0) == 0;
};

View File

@@ -28,8 +28,6 @@ goog.provide('Blockly.VariableModel');
goog.require('Blockly.Events.VarCreate');
goog.require('goog.string');
/**
* Class for a variable model.
@@ -97,5 +95,13 @@ Blockly.VariableModel.prototype.getId = function() {
* @package
*/
Blockly.VariableModel.compareByName = function(var1, var2) {
return goog.string.caseInsensitiveCompare(var1.name, var2.name);
var name1 = var1.name.toLowerCase();
var name2 = var2.name.toLowerCase();
if (name1 < name2) {
return -1;
} else if (name1 == name2) {
return 0;
} else {
return 1;
}
};

View File

@@ -33,7 +33,6 @@ goog.require('Blockly.constants');
goog.require('Blockly.VariableModel');
// TODO Fix circular dependencies
// goog.require('Blockly.Workspace');
goog.require('goog.string');
Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) {