  Non-overlapping codes are a set of codewords in $\bigcup_{n \ge 2}
\mathbb{Z}_q^n$, where $\mathbb{Z}_q = \{0,1,\dots,q-1\}$, such that, the
prefix of each codeword is not a suffix of any codeword in the set, including
itself; and for variable-length codes, a codeword does not contain any other
codeword as a subword. In this paper, we investigate a generic method to
generalize binary codes to $q$-ary for $q > 2$, and analyze this generalization
on the two constructions given by Levenshtein (also by Gilbert; Chee, Kiah,
Purkayastha, and Wang) and Bilotta, respectively. The generalization on the
former construction gives large non-expandable fixed-length non-overlapping
codes whose size can be explicitly determined; the generalization on the later
construction is the first attempt to generate $q$-ary variable-length
non-overlapping codes. More importantly, this generic method allows us to
utilize the generating function approach to analyze the cardinality of the
underlying $q$-ary non-overlapping codes. The generating function approach not
only enables us to derive new results, e.g., recurrence relations on their
cardinalities, new combinatorial interpretations for the constructions, and the
limit superior of their cardinalities for some special cases, but also greatly
simplifies the arguments for these results. Furthermore, we give an exact
formula for the number of fixed-length words that do not contain the codewords
in a variable-length non-overlapping code as subwords. This thereby solves an
open problem by Bilotta and induces a recursive upper bound on the maximum size
of variable-length non-overlapping codes.
