also noticed that it loops infinitely if the needle is empty, but the only meaningful thing to do here is to assert it being not empty as a precondition. You could maybe split character by character in that case, however that would be inconsistent with the overall behaviour of this split, as it does not ignore consecutive separators (it's a feature not a bug) and there are infinity consecutive empty strings between any two characters, or at the beginning of any string. You could also detect it and return some sentinel value, but to me that's an optional accessory that should go outside the main algorithm, because it can.
also noticed that it loops infinitely if the needle is empty, but the only meaningful thing to do here is to assert it being not empty as a precondition. You could maybe split character by character in that case, however that would be inconsistent with the overall behaviour of this split, as it does not ignore consecutive separators (it's a feature not a bug) and there are infinity consecutive empty strings between any two characters, or at the beginning of any string. You could also detect it and return some sentinel value, but to me that's an optional accessory that should go outside the main algorithm, because it can.