restrict strings for the choice to MaxLenInZChoice characters
354993
public void add(String item, String value) {

        int maxChar = MaxLenInZChoice;

        if (item.length() < MaxLenInZChoice) {
            maxChar = item.length();
        }

        super.add(item.substring(0, maxChar));
        values.addElement(value);
    }
934128
function validate ( inputOptions ) {

		var i, optionName, optionValue,
			filteredOptions = {};

		for ( i = 0; i < FormatOptions.length; i+=1 ) {

			optionName = FormatOptions[i];
			optionValue = inputOptions[optionName];

			if ( optionValue === undefined ) {

				// Only default if negativeBefore isn't set.
				if ( optionName === 'negative' && !filteredOptions.negativeBefore ) {
					filteredOptions[optionName] = '-';
				// Don't set a default for mark when 'thousand' is set.
				} else if ( optionName === 'mark' && filteredOptions.thousand !== '.' ) {
					filteredOptions[optionName] = '.';
				} else {
					filteredOptions[optionName] = false;
				}

			// Floating points in JS are stable up to 7 decimals.
			} else if ( optionName === 'decimals' ) {
				if ( optionValue >= 0 && optionValue < 8 ) {
					filteredOptions[optionName] = optionValue;
				} else {
					throw new Error(optionName);
				}

			// These options, when provided, must be functions.
			} else if ( optionName === 'encoder' || optionName === 'decoder' || optionName === 'edit' || optionName === 'undo' ) {
				if ( typeof optionValue === 'function' ) {
					filteredOptions[optionName] = optionValue;
				} else {
					throw new Error(optionName);
				}

			// Other options are strings.
			} else {

				if ( typeof optionValue === 'string' ) {
					filteredOptions[optionName] = optionValue;
				} else {
					throw new Error(optionName);
				}
			}
		}

		// Some values can't be extracted from a
		// string if certain combinations are present.
		throwEqualError(filteredOptions, 'mark', 'thousand');
		throwEqualError(filteredOptions, 'prefix', 'negative');
		throwEqualError(filteredOptions, 'prefix', 'negativeBefore');

		return filteredOptions;
	}
838845
function(value, maxLen, padChar) {
        value = value || '';
        return value + _getPadString(value, maxLen, padChar);
    }
773896
public static String maxLengthString(String... strings) {
        String res = "";
        for (String string : strings) {
            if (string.length() > res.length()) {
                res = string;
            }
        }
        return res;
    }
1348819
def set_selection_for_char char=nil
      char = _ask_a_char unless char
      #alert "got #{char} "
      return :UNHANDLED if char == :UNHANDLED
      @oldrow = @current_index
      @last_regex = /^#{char}/
      ix = next_regex @last_regex
      #alert "next returned #{ix}"
      return unless ix
      @current_index = ix[0] 
      @search_found_ix = @current_index
      @curpos = ix[1]
      ensure_visible
      return @current_index
    end
489713
def option_chooser(options, attr=None):
    
    for num, option in enumerate(options):
        if attr:
            print("%s: %s" % (num, getattr(option, attr)))
        else:
            print("%s: %s" % (num, option))
    # Add an escape option
    escape_opt = num + 1
    print("%s: I want to exit!" % escape_opt)
    choice = six.moves.input("Selection: ")
    try:
        ichoice = int(choice)
        if ichoice > escape_opt:
            raise ValueError
    except ValueError:
        print("Valid entries are the numbers 0-%s. Received '%s'." % (escape_opt,
                choice))
        sys.exit()

    if ichoice == escape_opt:
        print("Bye!")
        sys.exit()

    return ichoice
985028
private String limitString() {
        if(params.length != 2){
            throw new IllegalArgumentException("Wrong number of Parameters for limit string expression");
        }

        final String field = record.getValueByFieldName(params[0]);
        int limit = Integer.parseInt(params[1]);

        if (field.isEmpty() || field.length() < limit){
            return field;
        }

        String result = field.substring(0, limit) + "...";
        return result;
    }
1220288
def validate_MAXLEN(value, restriction):
    
    #Sometimes restriction values can accidentally be put in the template <item>100</items>,
    #Making them a list, not a number. Rather than blowing up, just get value 1 from the list.
    if type(restriction) is list:
        restriction = restriction[0]
    else:
        return

    if len(value) > restriction:
        raise ValidationError("MAXLEN: %s"%(restriction))
627554
private String limitStringLength(String str) {
    if (str.length() > MAX_STRING_LENGTH) {
      str = str.substring(0, MAX_STRING_LENGTH) + " ..."; 
    }
    return str;
  }
590929
def validate_args(opts):
    """"""
    if opts['--wide'] is None:
        opts['--wide'] = 2
    else:
        assert opts['--wide'] in ("1", "2"), opts['--wide']
    if opts['--alignment'] is None:
        opts['--alignment'] = 'left'
    else:
        assert opts['--alignment'] in ('left', 'right'), opts['--alignment']
    opts['--wide'] = int(opts['--wide'])
    opts['character_factory'] = WcWideCharacterGenerator
    if opts['--combining']:
        opts['character_factory'] = WcCombinedCharacterGenerator
    return opts
1178924
public Option choices(String... choices) throws RequiredParametersException {
		if (this.defaultValue != null) {
			if (Arrays.asList(choices).contains(defaultValue)) {
				Collections.addAll(this.choices, choices);
			} else {
				throw new RequiredParametersException("Valid values for option " + this.longName +
						" do not contain defined default value " + defaultValue);
			}
		} else {
			Collections.addAll(this.choices, choices);
		}
		return this;
	}
1352723
private void handleShortAndLongOption(String token) throws OptionParserException {
        if (token.length() == 1) {
            // -S
            if (options.hasShortOption(token)) {
                handleOption(options.getOption(token));
            } else {
                handleUnknownToken(currentToken);
            }
            return;
        }
        int pos = token.indexOf('=');
        if (pos == -1) {
            // no equal sign found (-xxx)
            if (options.hasShortOption(token)) {
                handleOption(options.getOption(token));
            } else if (!getMatchingLongOptions(token).isEmpty()) {
                // -L or -l
                handleLongOptionWithoutEqual(token);
            } else {
                // look for a long prefix (-Xmx512m)
                String name = getLongPrefix(token);
                if (name != null) {
                    Option option = options.getOption(name);
                    if (!option.isWithEqualSign() && option.acceptsValue()) {
                        handleOption(options.getOption(name));
                        currentOption.addValue(token.substring(name.length()));
                        currentOption = null;
                        return;
                    }
                }
                handleUnknownToken(currentToken);
            }
        } else {
            // equal sign found (-xxx=yyy)
            String name = token.substring(0, pos);
            String value = token.substring(pos + 1);
            // -S=V
            Option option = options.getOption(name);
            if (option != null && option.acceptsValue()) {
                handleOption(option);
                currentOption.addValue(value);
                currentOption = null;
            } else {
                // -L=V or -l=V
                handleLongOptionWithEqual(token);
            }
        }
    }
301893
static boolean isOctetStringValid(String value, int maxLength) {
        if (value == null)
            return true;
        if (value.length() > maxLength)
            return false;
        return true;
    }
441584
private void overAttributeChoice(CmsAttributeChoiceWidget choice) {

        cancelChoiceTimer();
        if (choice.getParent() != m_buttonBar) {
            closeAll();
            m_buttonBar = choice.getParent();
            setButtonBarVisibility(m_buttonBar, true);
        }
        if (m_choice != choice) {
            closeAllChoices();
            m_choice = choice;
            m_choice.show();
        }
    }
738491
public void validateRange(Config config, T value, Comparable<T> min, Comparable<T>  max) {
    boolean isValid = min.compareTo(value) <= 0 && 0 <= max.compareTo(value);
    if (!isValid) {
      throw new MorphlineCompilationException(
        String.format("Invalid choice: '%s' (choose from {%s..%s})", 
                      value, 
                      min,
                      max), 
        config);
    }
  }
1280599
def _user_submitted_barcode(max_length):
    '''
    
    '''
    barcode = input('BUTTON + SCAN: ').strip()
    if len(barcode) > max_length:
        raise Exception(BAD_BARCODE_MESSAGE.format(barcode))
    # remove all characters before the letter P
    # for example, remove ASCII selector code "\x1b(B" on chinese keyboards
    barcode = barcode[barcode.index('P'):]
    barcode = barcode.split('\r')[0].split('\n')[0]  # remove any newlines
    return barcode
1075815
def _setChoice(self,s,strict=0):
        """"""
        clist = _getChoice(s,strict)
        self.choice = list(map(self._coerceValue, clist))
        self._setChoiceDict()