Ported r2342 from ZXing

Original commit message: "Fix placement of ECI segment, which was wrong.
Add test. Try to clean up the legacy C++ port a bit more."