sal_uInt16 to size_t

Change-Id: Id60ca700d090dba30aeda7cdb3b3256a7fa3814e
Reuse common code

Change-Id: I8f1e8203f8318183fa327e96e53bdd0fb599ed89
Remove unneeded forward declaration

Change-Id: Ib650c1e191f5ed8f64bb8ac253e9f412b358e2e8
Use USHRT_MAX consistently, minor cleanups

Change-Id: I1a2906a350baf7af7141aaa6124930485578a604
Use an enum instead of a constant, and reduce its scope

Change-Id: Ica9d53103ffa98a72b27303352f2f3997a3386d5
sal_uInt16 to more proper integer types

Change-Id: I8a541e6466b66d6ca41e7b1556db3c72764582d1
Simplify and optimize booleans expressions

Change-Id: Ic5d736cdd48565c62958de72b08714922f1c56e5