Overte C++ Documentation
JSBaker.h
1 //
2 // JSBaker.h
3 // libraries/baking/src
4 //
5 // Created by Utkarsh Gautam on 9/18/17.
6 // Copyright 2017 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_JSBaker_h
13 #define hifi_JSBaker_h
14 
15 #include <QUrl>
16 
17 #include "Baker.h"
18 #include "JSBakingLoggingCategory.h"
19 
20 static const QString BAKED_JS_EXTENSION = ".baked.js";
21 
22 class JSBaker : public Baker {
23  Q_OBJECT
24 public:
25  JSBaker(const QUrl& jsURL, const QString& bakedOutputDir);
26  static bool bakeJS(const QByteArray& inputFile, QByteArray& outputFile);
27 
28  QString getJSPath() const { return _jsURL.toDisplayString(); }
29  QString getBakedJSFilePath() const { return _bakedJSFilePath; }
30 
31 public slots:
32  virtual void bake() override;
33 
34 signals:
35  void originalScriptLoaded();
36 
37 private slots:
38  void processScript();
39 
40 private:
41  void loadScript();
42  void handleScriptNetworkReply();
43 
44  QUrl _jsURL;
45  QByteArray _originalScript;
46  QString _bakedOutputDir;
47  QString _bakedJSFilePath;
48 
49  static void handleSingleLineComments(QTextStream& in);
50  static bool handleMultiLineComments(QTextStream& in);
51 
52  static bool canOmitSpace(QChar previousCharacter, QChar nextCharacter);
53  static bool canOmitNewLine(QChar previousCharacter, QChar nextCharacter);
54 
55  static bool isAlphanum(QChar c);
56  static bool isNonAscii(QChar c);
57  static bool isSpecialCharacter(QChar c);
58  static bool isSpecialCharacterPrevious(QChar c);
59  static bool isSpecialCharacterNext(QChar c);
60  static bool isSpaceOrTab(QChar c);
61  static bool isQuote(QChar c);
62 };
63 
64 #endif // !hifi_JSBaker_h