Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hmm, from your question I'm not totally clear on this point, but since you wanted some conversion I'm assuming that you want something that is at least human readable? </p> <p>Each OS may have different restrictions, but are you close enough to the platforms that you would be able to find out/test what is acceptable in a username? If you could find three 'special' characters that you could use just to do a replace on <code>'@', '.', '_'</code> you would be good to go. (Is that comprehensive? if not you would need to make sure you know all of them otherwise you could clash.) I searched a bit trying to find whether there was a POSIX standard, but wasn't able to find anything, so that's why I think if you can just test what's valid that would be the most direct route. </p> <p>With even one special character, you could do URL encoding, either with '%' if it's available, or whatever you choose if not, say '!", then <code>{ '@'-&gt;'!40", '_'-&gt;'!5F', '.'-&gt; '!2E' }</code>. (The spec [RFC1738] <a href="http://www.rfc-editor.org/rfc/rfc1738.txt" rel="nofollow">http://www.rfc-editor.org/rfc/rfc1738.txt</a>) defines the characters as US-ASCII so you can just find a table, e.g. in <a href="http://en.wikipedia.org/wiki/Ascii" rel="nofollow">wikipedia's ASCII article</a> and look up the correct hex digits there.) Or, you could just do your own simple mapping since you don't need the whole ASCII set, you could just do a map with two characters per escaped character and have, say, <code>'!a','!u','!p'</code> for at, underscore, period. </p> <p>If you have two special characters, say, '%', and '!', you could delimit text that represents the character, say, <code>%at!</code>, <code>&amp;us!</code>, and <code>'&amp;pd!'</code>. (This is pretty much html-style encoding, but instead of '&amp;' and ';' you are using the available ones, and you're making up your own mnemonics.) Another idea is that you could use runs of a symbol to determine the translated character, where each new character flops which symbol is being used. (This conveniently stops the run if we need to put two of the disallowed characters next to each other.) So assume '%' and '!', with period being 1, underscore 2, and at-sign being three, <code>'mickey._sample_@fake.out'</code> would become <code>'mickey%!!sample%%!!!fake%out'</code>. There are other variations but this one is easy to code.</p> <p>If none of this is an option (e.g. no symbols at all, just [a-zA-Z0-9]), then really I think the Base64 answer sounds about right. Really once we're getting to anything other than a simple replacement (and even that) it's already getting hard to type if that's the goal. But if you really need to try to keep the email mostly readable, what you do is implement some sort of escaping. I'm thinking use '0' as your escape character, so now '0' becomes '00', '@' becomes '01', '.' becomes '02', and '_' becomes '03'. So now, <code>'mickey01._sample_@fake.out'</code>would become <code>'mickey0010203sample0301fake02out'</code>. Not beautiful but it should work; since we escaped any raw 0's, just always make sure you define a mapping for whatever you choose as your escape char and you should be fine..</p> <p>That's all I can think of atm. :) Definitely if there's no need for these usernames to be readable in the raw it seems like apparently Base64 won't work, since it can produce slashes. Heck, ok, just the 2-digit US-ASCII hex value for each character and you're done...] <strike>is a good way to go; there's lots of nice debugged, heavily field-tested code out there for it and it solves your problem quite handily.</strike> :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload