Commit 746343f3 authored by Evan W. Patton's avatar Evan W. Patton

Add is-text? block to test for whether a value is a string

Change-Id: Ib30e302ecf5f19970532bab66e409e50aed08b40
parent 6e23c47c
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2013-2014 MIT, All rights reserved
// Copyright 2013-2017 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
/**
......@@ -474,3 +474,17 @@ Blockly.Blocks['obfuscated_text'] = {
},
typeblock: [{translatedName: Blockly.Msg.LANG_TEXT_TEXT_OBFUSCATE}]
};
Blockly.Blocks['text_is_string'] = {
category: 'Text',
helpUrl: Blockly.Msg.LANG_TEXT_TEXT_IS_STRING_HELPURL,
init: function() {
this.setColour(Blockly.TEXT_CATEGORY_HUE);
this.appendValueInput('ITEM')
.appendField(Blockly.Msg.LANG_TEXT_TEXT_IS_STRING_TITLE)
.appendField(Blockly.Msg.LANG_TEXT_TEXT_IS_STRING_INPUT_THING);
this.setOutput(true, Blockly.Blocks.Utilities.YailTypeToBlocklyType("boolean", Blockly.Blocks.Utilities.OUTPUT));
this.setTooltip(Blockly.Msg.LANG_TEXT_TEXT_IS_STRING_TOOLTIP);
},
typeblock: [{translatedName: Blockly.Msg.LANG_TEXT_TEXT_IS_STRING_TITLE}]
};
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2012 Massachusetts Institute of Technology. All rights reserved.
// Copyright 2012-2017 Massachusetts Institute of Technology. All rights reserved.
/**
* @license
* @fileoverview Color blocks yail generators for Blockly, modified for MIT App Inventor.
* @fileoverview Text blocks yail generators for Blockly, modified for MIT App Inventor.
* @author mckinney@mit.edu (Andrew F. McKinney)
*/
......@@ -304,3 +304,16 @@ Blockly.Yail['obfuscated_text'] = function() {
+ Blockly.Yail.YAIL_DOUBLE_QUOTE + Blockly.Yail.YAIL_CLOSE_COMBINATION;
return [ code, Blockly.Yail.ORDER_ATOMIC ];
};
Blockly.Yail['text_is_string'] = function() {
// Check if the argument is a string
var argument0 = Blockly.Yail.valueToCode(this, 'ITEM', Blockly.Yail.ORDER_NONE) || Blockly.Yail.YAIL_FALSE;
var code = Blockly.Yail.YAIL_CALL_YAIL_PRIMITIVE + "string?" + Blockly.Yail.YAIL_SPACER;
code = code + Blockly.Yail.YAIL_OPEN_COMBINATION + Blockly.Yail.YAIL_LIST_CONSTRUCTOR + Blockly.Yail.YAIL_SPACER;
code = code + argument0;
code = code + Blockly.Yail.YAIL_SPACER + Blockly.Yail.YAIL_CLOSE_COMBINATION;
code = code + Blockly.Yail.YAIL_SPACER + Blockly.Yail.YAIL_QUOTE + Blockly.Yail.YAIL_OPEN_COMBINATION;
code = code + "any" + Blockly.Yail.YAIL_CLOSE_COMBINATION + Blockly.Yail.YAIL_SPACER;
code = code + Blockly.Yail.YAIL_DOUBLE_QUOTE + "is a string?" + Blockly.Yail.YAIL_DOUBLE_QUOTE + Blockly.Yail.YAIL_CLOSE_COMBINATION;
return [ code, Blockly.Yail.ORDER_ATOMIC ];
};
......@@ -5,7 +5,7 @@
* Visual Blocks Language
*
* Copyright © 2012 Google Inc.
* Copyright © 2012-2016 Massachusetts Institute of Technology
* Copyright © 2012-2017 Massachusetts Institute of Technology
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -710,6 +710,11 @@ Blockly.Msg.en.switch_language_to_english = {
Blockly.Msg.LANG_TEXT_REPLACE_ALL_TOOLTIP = 'Returns a new text obtained by replacing all occurrences\n'
+ 'of the segment with the replacement.';
Blockly.Msg.LANG_TEXT_TEXT_IS_STRING_HELPURL = 'http://appinventor.mit.edu/explore/ai2/support/blocks/text#isstring';
Blockly.Msg.LANG_TEXT_TEXT_IS_STRING_TITLE = 'is a string?';
Blockly.Msg.LANG_TEXT_TEXT_IS_STRING_INPUT_THING = 'thing';
Blockly.Msg.LANG_TEXT_TEXT_IS_STRING_TOOLTIP = 'Returns true if <code>thing</code> is a string.';
// Lists Blocks.
Blockly.Msg.LANG_CATEGORY_LISTS = 'Lists';
//Blockly.Msg.LANG_LISTS_CREATE_EMPTY_HELPURL = 'http://en.wikipedia.org/wiki/Linked_list#Empty_lists';
......
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright © 2013-2016 Massachusetts Institute of Technology, All rights reserved
// Copyright © 2013-2017 Massachusetts Institute of Technology, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
/**
......@@ -1667,7 +1667,10 @@ Blockly.Versioning.AllUpgradeMaps =
// AI2: In BLOCKS_LANGUAGE_VERSION 20// Rename 'obsufcated_text' text block to 'obfuscated_text'
20: Blockly.Versioning.renameBlockType('obsufcated_text', 'obfuscated_text')
20: Blockly.Versioning.renameBlockType('obsufcated_text', 'obfuscated_text'),
// AI2: Added is a string? block to test whether values are strings.
21: "noUpgrade"
}, // End Language upgraders
......
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Copyright 2011-2017 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
......@@ -399,8 +399,10 @@ public class YaVersion {
// - FORM_COMPONENT_VERSION was incremented to 20
// For YOUNG_ANDROID_VERSION_160:
// - FORM_COMPONENT_VERSION was incremented to 21
// For YOUNG_ANDROID_VERSION_161:
// - BLOCKS_LANGUAGE_VERSION was incremented to 21
public static final int YOUNG_ANDROID_VERSION = 160;
public static final int YOUNG_ANDROID_VERSION = 161;
// ............................... Blocks Language Version Number ...............................
......@@ -460,8 +462,10 @@ public class YaVersion {
// The number-convert blocks was added
// For BLOCKS_LANGUAGE_VERSION 20:
// - Spelling of "Obsfucate" was corrected to Obfuscate in Text Block
// For BLOCKS_LANGUAGE_VERSION 21:
// - The is-text block was added.
public static final int BLOCKS_LANGUAGE_VERSION = 20;
public static final int BLOCKS_LANGUAGE_VERSION = 21;
// ................................. Component Version Numbers ..................................
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment