Consolidate "safe identifier" code by introducing qbs.rfc1034identifier.

Instead of duplicating this logic in three places across two languages,
it's now implemented in a central location in C++ and exposed to
JavaScript. As an intentional side effect, build directory naming now
uses - instead of _ as per the RFC 1034 name charset.

Change-Id: I1a7c3ec45efc5b29f9a05067e4c2cf640af4a7aa
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>