/* The input string may contain NARROW_CHAR and WIDE_CHAR. Notice: the input string doesn't contain line break characters. */
VOID GetStringOffsetWithWidth(IN CHAR16 *String, IN UINTN MaxWidth, OUT UINTN *Offset)
/* The input string may contain NARROW_CHAR and WIDE_CHAR. Notice: the input string doesn't contain line break characters. */
VOID GetStringOffsetWithWidth(IN CHAR16 *String, IN UINTN MaxWidth, OUT UINTN *Offset)
{
  UINTN  StringWidth;
  UINTN  CharWidth;
  UINTN  StrOffset;
  StringWidth = 0;
  CharWidth   = 1;
  for (StrOffset = 0; String[StrOffset] != CHAR_NULL; StrOffset++) {
    switch (String[StrOffset]) {
      case NARROW_CHAR:
        CharWidth = 1;
        break;
      case WIDE_CHAR:
        CharWidth = 2;
        break;
      default:
        StringWidth += CharWidth;
        if (StringWidth >= MaxWidth) {
          *Offset = StrOffset;
          return;
        }
    }
  }
  *Offset = StrOffset;
}