Natural Sort (Part 2 of 3)

Before comparing strings we need to identify the text and the numeric parts in the string. The algorithm is very simple: iterate each character of the string, if we find a character that is not a digit, start a Characters chunk, if it’s a digit, create a new Number chunk. Process the next character. If it’s of the same kind than the previous one, then store it in a buffer and continue. If it’s not of the same type, then store the current buffer as a chunk part alongside it’s type, then create a new buffer and set the correct chunk type for it. Repeat the process until the end of the string.