Skip to content

Commit

Permalink
basic unicode support
Browse files Browse the repository at this point in the history
Task #127 - provide basic unicode support in cyacas
  • Loading branch information
grzegorzmazur committed Sep 27, 2015
1 parent 8ff4b8c commit 0ac7f6a
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 313 deletions.
5 changes: 3 additions & 2 deletions include/yacas/commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

#include "lispstring.h"
#include "yacasbase.h"
#include "utf8.h"

enum ESpecialChars
{
eDelete = 0x1000,
eDelete = utf8::internal::CODE_POINT_MAX + 1,
eBackSpace,
eLeft,
eRight,
Expand Down Expand Up @@ -90,7 +91,7 @@ class CCommandLine : public YacasBase
/** return a key press, which is either an ascii value, or one
* of the values specified in ESpecialChars
*/
virtual LispInt GetKey() = 0;
virtual char32_t GetKey() = 0;
/// Go to the next line on the console (carriage return/line feed).
virtual void NewLine() = 0;
/** Show the current line (in iSubLine), with the required prompt,
Expand Down
8 changes: 2 additions & 6 deletions include/yacas/lispio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
#ifndef YACAS_LISPIO_H
#define YACAS_LISPIO_H

#include "yacasbase.h"

#include <cstddef>
#include <string>

// Hope this forward declaration doesn't screw us over...
class InputDirectories;
class InputStatus
{
public:
Expand Down Expand Up @@ -73,12 +69,12 @@ class LispInput
virtual ~LispInput() = default;

/// Return the next character in the file
virtual LispChar Next() = 0;
virtual char32_t Next() = 0;

/** Peek at the next character in the file, without advancing the file
* pointer.
*/
virtual LispChar Peek() = 0;
virtual char32_t Peek() = 0;

virtual const InputStatus& Status() const {return iStatus;};

Expand Down
60 changes: 14 additions & 46 deletions include/yacas/platfileio.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define YACAS_PLATFILEIO_H

#include "noncopyable.h"
#include "yacasbase.h"

#include <fstream>
#include <iostream>
Expand All @@ -21,41 +20,25 @@ class LispLocalFile: NonCopyable {
LispEnvironment& environment;
};


class StdFileInput : public LispInput
{
class StdFileInput : public LispInput {
public:
virtual LispChar Next();
virtual LispChar Peek();
virtual bool EndOfStream() const;
void Rewind();
virtual std::size_t Position() const;
virtual void SetPosition(std::size_t aPosition);

protected:
StdFileInput(std::istream&, InputStatus& aStatus);
StdFileInput(LispLocalFile& aFile,InputStatus& aStatus);

std::istream& stream;
};


/** CachedStdFileInput : same as StdFileInput, but with caching
* for speed */
class CachedStdFileInput: public StdFileInput, NonCopyable {
public:
CachedStdFileInput(LispLocalFile& aFile,InputStatus& aStatus);

LispChar Next();
LispChar Peek();
bool EndOfStream() const;
void Rewind();
std::size_t Position() const;
void SetPosition(std::size_t aPosition);

char32_t Next() override;
char32_t Peek() override;
bool EndOfStream() const override;
virtual void Rewind();
std::size_t Position() const override;
void SetPosition(std::size_t) override;

private:
std::vector<LispChar> _buf;
std::size_t iCurrentPos;
void _get() const;

std::istream& _stream;
std::size_t _position;
mutable bool _cp_ready;
mutable char32_t _cp;
};

class StdUserInput: public StdFileInput {
Expand All @@ -66,21 +49,6 @@ class StdUserInput: public StdFileInput {
}
};

class CachedStdUserInput: public StdUserInput {
public:
CachedStdUserInput(InputStatus& aStatus);

virtual LispChar Next();
virtual LispChar Peek();
virtual bool EndOfStream() const;
void Rewind();
virtual std::size_t Position() const;

private:
LispString iBuffer;
std::size_t iCurrentPos;
};


std::string InternalFindFile(const LispChar* fname, const std::vector<std::string>& dirs);

Expand Down
10 changes: 5 additions & 5 deletions include/yacas/stdcommandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class CStdCommandLine : public CCommandLine
{
public:
void ReadLine(const std::string& prompt);
void ReadLine(const std::string& prompt) override;
public:
LispInt GetKey();
void NewLine();
void ShowLine(const std::string& prompt, unsigned cursor);
void Pause();
char32_t GetKey() override;
void NewLine() override;
void ShowLine(const std::string& prompt, unsigned cursor) override;
void Pause() override;
};


Expand Down
21 changes: 11 additions & 10 deletions include/yacas/stringio.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
#ifndef YACAS_STRINGIO_H
#define YACAS_STRINGIO_H

#include "yacasbase.h"
#include "lispio.h"
#include "lispstring.h"
#include "utf8.h"

#include <string>

class StringInput : public LispInput
{
public:
StringInput(const std::string& aString, InputStatus& aStatus);
virtual LispChar Next();
virtual LispChar Peek();
virtual bool EndOfStream() const;
virtual std::size_t Position() const;
virtual void SetPosition(std::size_t aPosition);
StringInput(const std::string&, InputStatus&);
char32_t Next() override;
char32_t Peek() override;
bool EndOfStream() const override;
std::size_t Position() const override;
void SetPosition(std::size_t aPosition) override;
protected:
std::string iString;
std::size_t iCurrent;
std::string _string;
std::string::const_iterator _current;
};

#endif
Expand Down
10 changes: 5 additions & 5 deletions include/yacas/unixcommandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class CUnixCommandLine : public CCommandLine
CUnixCommandLine();
~CUnixCommandLine();

LispInt GetKey();
void NewLine();
void ShowLine(const std::string& prompt, unsigned cursor);
void Pause();
void MaxHistoryLinesSaved(std::size_t);
char32_t GetKey() override;
void NewLine() override;
void ShowLine(const std::string& prompt, unsigned cursor) override;
void Pause() override;
void MaxHistoryLinesSaved(std::size_t) override;

private:
unsigned char term_chars[NCCS];
Expand Down
10 changes: 5 additions & 5 deletions include/yacas/win32commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class CWin32CommandLine : public CCommandLine
CWin32CommandLine();
~CWin32CommandLine();

LispInt GetKey();
void NewLine();
void ShowLine(const std::string& prompt, unsigned cursor);
void Pause();
void MaxHistoryLinesSaved(std::size_t);
char32_t GetKey() override;
void NewLine() override;
void ShowLine(const std::string& prompt, unsigned cursor) override;
void Pause() override;
void MaxHistoryLinesSaved(std::size_t) override;

private:
void color_print(const std::string& str, WORD text_attrib);
Expand Down
2 changes: 1 addition & 1 deletion include/yacas/yacas.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DefaultYacasEnvironment: NonCopyable
LispEnvironment iEnvironment;

public:
CachedStdUserInput input;
StdUserInput input;
};


Expand Down

0 comments on commit 0ac7f6a

Please sign in to comment.