01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.tools.generators;
10:
11: /**
12: * @author Gennady Krizhevsky
13: */
14: class MonoBuffer {
15: private Case currentCase = null;
16: private boolean caseChanged = false;
17: private boolean fromUpperToLower = false;
18: private boolean fromLowerToUpper = false;
19: private StringBuffer bufferMinus1;
20: private StringBuffer bufferMinus2;
21: private StringBuffer buffer = new StringBuffer();
22:
23: public MonoBuffer append(char ch) {
24: if (Character.isUpperCase(ch) || Character.isDigit(ch)/* || ch == '_'*/) {
25: handleCaseChange(Case.UPPER_CASE);
26: } else {
27: handleCaseChange(Case.LOWER_CASE);
28: }
29:
30: if (caseChanged) {
31: bufferMinus2 = bufferMinus1;
32: bufferMinus1 = buffer;
33: buffer = new StringBuffer();
34: }
35: buffer.append(ch);
36: return this ;
37: }
38:
39: private void handleCaseChange(Case futureCurrentCase) {
40: if (currentCase == Case.oppositeOf(futureCurrentCase)) {
41: caseChanged = true;
42: fromLowerToUpper = futureCurrentCase == Case.UPPER_CASE;
43: fromUpperToLower = !fromLowerToUpper;
44: } else {
45: caseChanged = false;
46: }
47: currentCase = futureCurrentCase;
48: }
49:
50: public Case getCurrentCase() {
51: return currentCase;
52: }
53:
54: public boolean isCaseChanged() {
55: return caseChanged;
56: }
57:
58: public StringBuffer getBufferMinus1() {
59: return bufferMinus1;
60: }
61:
62: public StringBuffer getBufferMinus2() {
63: return bufferMinus2;
64: }
65:
66: public int bufferSize() {
67: return buffer == null ? 0 : buffer.length();
68: }
69:
70: public int bufferMinus1Size() {
71: return bufferMinus1 == null ? 0 : bufferMinus1.length();
72: }
73:
74: public int bufferMinus2Size() {
75: return bufferMinus2 == null ? 0 : bufferMinus2.length();
76: }
77:
78: public boolean isFromUpperToLower() {
79: return fromUpperToLower;
80: }
81:
82: public boolean isFromLowerToUpper() {
83: return fromLowerToUpper;
84: }
85:
86: public String toString() {
87: return buffer.toString();
88: }
89:
90: }
|