/*
* Copyright (C) 1996-2000,2002,2007 Michael R. Elkins <me@mutt.org>
+ * Copyright (C) 2016 Richard Russon <rich@flatcap.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
return 2;
}
+/**
+ * get_nth_wchar - Extract one char from a utf-8 string
+ * @ustr: Unicode string
+ * @index: Select this character
+ * @return: String pointer to the character
+ *
+ * Extract one multi-byte character from a string.
+ * If the (index < 0) the first character will be selected.
+ * If the index is larger thant the string, then " " will be returned.
+ * If the character selected is '\n' (Ctrl-M), then "" will be returned.
+ *
+ * Note: get_nth_wchar() may return a pointer to a static buffer.
+ */
+char *get_nth_wchar (char *ustr, int index)
+{
+ static char buffer[5];
+ int clen = 0;
+ int i;
+
+ if (!*ustr)
+ return " ";
+
+ for (i = 0; i <= index; i++)
+ {
+ ustr += clen;
+ clen = mutt_charlen (ustr, NULL);
+ if (clen < 1)
+ return " ";
+ }
+
+ if ((clen == 1) && (ustr[0] == '\r'))
+ return "";
+
+ memcpy (buffer, ustr, clen);
+ buffer[clen] = 0;
+ return buffer;
+}
+
static void make_from (ENVELOPE *hdr, char *buf, size_t len, int do_lists)
{
int me;