<p>
Pads or truncates a string to a specified length.
</p>

@param text
String to be fixed
@param charsNum
The fixed length in number of chars
@param paddingChar
The padding character
@param left
true for left padding
@return A fixed length string
976126
public static String fixLength(final String text, final int charsNum, final char paddingChar, final boolean left)
    {
        Preconditions.checkArgument(charsNum > 0, "The number of characters must be greater than zero.");

        String str = text == null ? "" : text;
        String fmt = String.format("%%%ss", left ? charsNum : -charsNum);

        return String.format(fmt, str).substring(0, charsNum).replace(' ', paddingChar);
    }
738773
public function truncate($text, $length = 15)
    {
        if (!$this->isValidLength($text, $length)) return $text;
        return (\strlen($text) > $length) ? $this->left($text, $length) . '...' : $text;
    }
1364665
public AT_Row setPaddingLeftChar(Character paddingLeftChar) {
		if(this.hasCells()){
			for(AT_Cell cell : this.getCells()){
				cell.getContext().setPaddingLeftChar(paddingLeftChar);
			}
		}
		return this;
	}
849809
private String cleanAndTrimString(String text, int maxTextLength) {
        if (StringUtils.isNotBlank(text)) {
            String cleaned = text.trim().replaceAll("[\\s]+", " ");
            return cleaned.length() <= maxTextLength
                    ? cleaned
                    : cleaned.substring(0, maxTextLength) + " ...";
        }
        return text;
    }
944886
public AsciiTable setPaddingBottomChar(Character paddingBottomChar) {
		for(AT_Row row : this.rows){
			if(row.getType()==TableRowType.CONTENT){
				row.setPaddingBottomChar(paddingBottomChar);
			}
		}
		return this;
	}
178351
def pad(text, bits=32):
    
    return text + (bits - len(text) % bits) * chr(bits - len(text) % bits)
916408
public static String lpad(String base, int len, String pad) {
		if (len < 0 || "".equals(pad)) {
			return null;
		} else if (len == 0) {
			return "";
		}

		char[] data = new char[len];
		char[] baseChars = base.toCharArray();
		char[] padChars = pad.toCharArray();

		// the length of the padding needed
		int pos = Math.max(len - base.length(), 0);

		// copy the padding
		for (int i = 0; i < pos; i += pad.length()) {
			for (int j = 0; j < pad.length() && j < pos - i; j++) {
				data[i + j] = padChars[j];
			}
		}

		// copy the base
		int i = 0;
		while (pos + i < len && i < base.length()) {
			data[pos + i] = baseChars[i];
			i += 1;
		}

		return new String(data);
	}
490787
public AsciiTable setPaddingTopChar(Character paddingTopChar) {
		for(AT_Row row : this.rows){
			if(row.getType()==TableRowType.CONTENT){
				row.setPaddingTopChar(paddingTopChar);
			}
		}
		return this;
	}
351429
def _pad(string, size):
    
    strlen = len(string)
    if strlen == size:
        return string
    if strlen < size:
        return _padding[0:size-strlen] + string
    return string[-size:]
561089
def pad_char(text: str, width: int, char: str = '\n') -> str:
    """"""
    dis = width - len(text)
    if dis < 0:
        raise ValueError
    if dis > 0:
        text += char * dis
    return text
154038
public static function padLeft(string $str, int $length, string $with = ' ', string $encoding = null) : string
    {
        return static::pad($str, $length, $with, STR_PAD_LEFT, $encoding);
    }
746221
function pad(number, size) {
        var stringNum = String(number);

        while (stringNum.length < (size || 2)) {
            stringNum = '0' + stringNum;
        }

        return stringNum;
    }
1125782
public static String left(EvaluationContext ctx, Object text, Object numChars) {
        int _numChars = Conversions.toInteger(numChars, ctx);
        if (_numChars < 0) {
            throw new RuntimeException("Number of chars can't be negative");
        }

        return StringUtils.left(Conversions.toString(text, ctx), _numChars);
    }
521706
public function pad($input, $padLength, $padString, $padType = STR_PAD_RIGHT) {
		$length = mb_strlen($input);
		if ($padLength - $length > 0) {
			switch ($padType) {
				case STR_PAD_LEFT:
					$input = str_repeat($padString, $padLength - $length) . $input;
					break;
				case STR_PAD_RIGHT:
					$input .= str_repeat($padString, $padLength - $length);
					break;
			}
		}
		return $input;
	}
1240047
public static String leftPad(final String value, final String pad, final int length) {
        validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
        validate(pad, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
        if (value.length() > length) {
            return value;
        }
        return append(repeat(pad, length - value.length()), value);
    }
501863
public static String pad(String rawString, int length, char padChar)
  {
    String padded = rawString;
    String padFiller = null;

    if (padded.length() == length)
    {
      return padded;
    }

    if (padded.length() < length)
    {
      //
      // Keep a zero string that is big enough to pad the
      // largest field that we have, then to pad each field
      // we just append this string to the field and then
      // substr to the desired size.
      //
      StringBuffer buff = new StringBuffer(length);

      for (int i = buff.length(); i < length; i++)
      {
        buff.append(padChar);
      }
      padFiller = buff.toString();

      padded = rawString + padFiller;
      return padded.substring(0, length);

    }
    else
    {
      return padded.substring(0, length);
    }
  }
944339
public T padding(Integer... padding) {
        if (padding != null && padding.length > 4) {
            throw new RuntimeException("padding属性最多可以接收4个参数!");
        }
        this.padding = padding;
        return (T) this;
    }