mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
New blocks text_count, text_replace, and text_reverse (#830)
Includes generators for all languages and units tests on those generators.
This commit is contained in:
committed by
Andrew n marshall
parent
fb0f1b05dd
commit
34750bccd8
@@ -251,3 +251,30 @@ Blockly.Python['text_prompt_ext'] = function(block) {
|
||||
};
|
||||
|
||||
Blockly.Python['text_prompt'] = Blockly.Python['text_prompt_ext'];
|
||||
|
||||
Blockly.Python['text_count'] = function(block) {
|
||||
var text = Blockly.Python.valueToCode(block, 'TEXT',
|
||||
Blockly.Python.ORDER_MEMBER) || '\'\'';
|
||||
var sub = Blockly.Python.valueToCode(block, 'SUB',
|
||||
Blockly.Python.ORDER_NONE) || '\'\'';
|
||||
var code = text + '.count(' + sub + ')';
|
||||
return [code, Blockly.Python.ORDER_MEMBER];
|
||||
};
|
||||
|
||||
Blockly.Python['text_replace'] = function(block) {
|
||||
var text = Blockly.Python.valueToCode(block, 'TEXT',
|
||||
Blockly.Python.ORDER_MEMBER) || '\'\'';
|
||||
var from = Blockly.Python.valueToCode(block, 'FROM',
|
||||
Blockly.Python.ORDER_NONE) || '\'\'';
|
||||
var to = Blockly.Python.valueToCode(block, 'TO',
|
||||
Blockly.Python.ORDER_NONE) || '\'\'';
|
||||
var code = text + '.replace(' + from + ', ' + to + ')';
|
||||
return [code, Blockly.Python.ORDER_MEMBER];
|
||||
};
|
||||
|
||||
Blockly.Python['text_reverse'] = function(block) {
|
||||
var text = Blockly.Python.valueToCode(block, 'TEXT',
|
||||
Blockly.Python.ORDER_MEMBER) || '\'\'';
|
||||
var code = text + '[::-1]';
|
||||
return [code, Blockly.Python.ORDER_MEMBER];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user