Example #1
0
///////////////////////////////////////////////////////////////////////////////
// test_dynamic
void test_dynamic()
{
    typedef std::vector<UChar>::const_iterator uchar_iterator;
    typedef basic_regex<uchar_iterator> uregex;
    typedef match_results<uchar_iterator> umatch;
    typedef regex_compiler<uchar_iterator, UChar_traits> uregex_compiler;

    std::string pattern_("b.*r"), str_("foobarboo");
    std::vector<UChar> pattern(pattern_.begin(), pattern_.end());
    std::vector<UChar> str(str_.begin(), str_.end());

    UChar_traits tr;
    uregex_compiler compiler(tr);
    uregex urx = compiler.compile(pattern);
    umatch what;

    if(!regex_search(str, what, urx))
    {
        BOOST_ERROR("regex_search on UChar failed");
    }
    else
    {
        BOOST_CHECK_EQUAL(3, what.position());
        BOOST_CHECK_EQUAL(3, what.length());
    }

    // test for range-based regex_replace
    std::vector<UChar> output = regex_replace(str, urx, pattern_);
    std::string output_(output.begin(), output.end());
    std::string expected("foob.*rboo");
    BOOST_CHECK_EQUAL(output_, expected);
}
Example #2
0
StructuredScript::IAny::Ptr StructuredScript::Nodes::EchoNode::evaluate(IStorage *storage, IExceptionManager *exception, INode *expr){
	auto value = value_->evaluate(storage, exception, expr);
	if (Query::ExceptionManager::has(exception))
		return nullptr;

	auto str = str_(value, storage, exception, expr);
	if (Query::ExceptionManager::has(exception))
		return nullptr;

	std::cout << str << "\n";
	return PrimitiveFactory::createUndefined();
}
Example #3
0
/** QString QObject::objectName() const
 * bind/QObject.h:7
 */
static int TableView_objectName(lua_State *L) {
  try {
    TableView *self = *((TableView **)dub_checksdata(L, 1, "mimas.TableView"));
    QByteArray str_(self->objectName().toUtf8());
    lua_pushlstring(L, str_.constData(), str_.size());
    return 1;
  } catch (std::exception &e) {
    lua_pushfstring(L, "objectName: %s", e.what());
  } catch (...) {
    lua_pushfstring(L, "objectName: Unknown exception");
  }
  return dub_error(L);
}
Example #4
0
/** QString QLineEdit::text() const
 * bind/QLineEdit.h:12
 */
static int LineEdit_text(lua_State *L) {
  try {
    LineEdit *self = *((LineEdit **)dub_checksdata(L, 1, "mimas.LineEdit"));
    QByteArray str_(self->text().toUtf8());
    lua_pushlstring(L, str_.constData(), str_.size());
    return 1;
  } catch (std::exception &e) {
    lua_pushfstring(L, "text: %s", e.what());
  } catch (...) {
    lua_pushfstring(L, "text: Unknown exception");
  }
  return dub_error(L);
}
Example #5
0
/** QString Widget::cssClass() const
 * include/mimas/Widget.h:71
 */
static int Widget_cssClass(lua_State *L) {
  try {
    Widget *self = *((Widget **)dub_checksdata(L, 1, "mimas.Widget"));
    QByteArray str_(self->cssClass().toUtf8());
    lua_pushlstring(L, str_.constData(), str_.size());
    return 1;
  } catch (std::exception &e) {
    lua_pushfstring(L, "cssClass: %s", e.what());
  } catch (...) {
    lua_pushfstring(L, "cssClass: Unknown exception");
  }
  return dub_error(L);
}
Example #6
0
void CKaiDoc::v_CreateDeafultParagraph (CT_Paragraph *& pco_paragraph)
{
    int i_defaultLineWidth = 0;
    int i_defaultLeftIndent = 0;
    int i_defaultRightIndent = 0;
    int i_defaultSpacing = 0;
    ET_Alignment eo_defaultAlignment = ec_AlignmentFront;

    bool b_ = pco_Doc_->b_GetDefaultParStyle (i_defaultLineWidth,
                                              i_defaultLeftIndent,
                                              i_defaultRightIndent,
                                              eo_defaultAlignment);
    if (!b_)
    {
        STL_STRING str_ (_T("Warning: Unable to find default paragraph style"));
        ERROR_TRACE (str_);
        i_defaultLineWidth = 800;
        i_defaultSpacing = 10;
        eo_defaultAlignment = ec_Left;
    }

    pco_Doc_->v_SetMaxParagraphWidth (i_defaultLineWidth);

    STL_STRING str_typeface;
    int i_size = 0;
    ET_Charset eo_charset = ec_CharsetFront;
    b_ = pco_Doc_->b_GetDefaultFont (str_typeface, i_size, eo_charset);
    if (!b_)
    {
        ERROR_TRACE (_T("Warning: b_GetDefaultFont returned \"false\""));
        str_typeface = _T("Courier New");
        i_size = 10;
        eo_charset = ec_RussianCharset;
    }

    CT_FontDescriptor co_fd (CT_KaiString (str_typeface), eo_charset, i_size);
    pco_Doc_->v_CreateDefaultParagraph (i_defaultLeftIndent,
                                        i_defaultRightIndent,
                                        eo_defaultAlignment,
                                        STL_STRING(_T("")),
                                        co_fd,
                                        pco_paragraph);

}    //  v_CreateDeafultParagraph (...)
Example #7
0
void CKaiDoc::OnFileSaveAs()
{
    // TODO: Add your command handler code here
    CString cstr_path = GetPathName();
    if (!cstr_path.IsEmpty())
    {
        CString cstr_ext = PathFindExtension (cstr_path);
        cstr_path = CString (cstr_path.Left (cstr_path.GetLength() - 
                             cstr_ext.GetLength()) + 
                             _T(".kai"));
    }
    else
    {
        SetTitle (pco_Doc_->str_Title_.data());
    }

//    CDocument::OnFileSaveAs();

    bool b_continue = false;
    INT_PTR i_ret = 0;
    do
    {
        CFileDialog co_dlg (FALSE, // i.e. use Save As dlg template
                            _T("*.kai"), 
                            cstr_path, 
                            OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
                            _T("Kai Documents|*.kai|Unicode Texts|*.txt|All Files|*.*||"));

        i_ret = co_dlg.DoModal();

        if (IDOK == i_ret)
        {
            if (1 == co_dlg.m_ofn.nFilterIndex)     // *.kai (it's zero-based)
            {
                try
                {
                    CFile co_file (co_dlg.GetPathName(), CFile::modeWrite | CFile::modeCreate);
                    bool b_result = pco_Doc_->b_Store (co_file);
                    if (b_result)
                    {
                        SetTitle (co_dlg.GetFileName());
                        v_ClearModified();
                        pco_Doc_->b_Imported_ = false;
                    }
                }
                catch (CFileException * pco_ex)
                {
                    STL_STRING str_ (_T("Unable to save document. "));
                    TCHAR psz_errData[1000] = { 0 };
                    pco_ex->GetErrorMessage (psz_errData, 1000);
                    str_ += STL_STRING (psz_errData);
                    str_ += _T(".");
                    ERROR_TRACE (str_);
                    AfxMessageBox (str_.c_str(), MB_ICONEXCLAMATION);
                }
            }
            else
            {
                CString cstr_text (_T("You chose to save the document as a Unicode text. "));
                cstr_text += _T("\nFormatting, linguistic data, and some diacritics may be lost. ");
                cstr_text += _T("\nTo continue, click OK. To keep all data, click Cancel and then ");
                cstr_text += _T("\nselect the \"Kai Documents\" option from the menu");
                int i_ret = AfxMessageBox (cstr_text, MB_ICONEXCLAMATION | MB_OKCANCEL);
                if (IDOK == i_ret)
                {
                    CFile co_file (co_dlg.GetPathName(), CFile::modeWrite | CFile::modeCreate);
                    bool b_result = pco_Doc_->b_StoreAsPlainText (co_file);
                    if (b_result)
                    {
                        SetTitle (co_dlg.GetFileName());
                        v_ClearModified();
                        pco_Doc_->b_Imported_ = false;
                    }
                }
                else
                {
                    if (IDCANCEL == i_ret)
                    {
                        b_continue = true;
                    }
                    else
                    {
                        ERROR_TRACE (_T("Unexpected return from AfxMessageBox"));
                        AfxMessageBox (_T("Internal error. Unable to save document."), 
                                       MB_ICONEXCLAMATION);
                    }
                }
            }

        }   //  if (IDOK == i_ret)
        else
        {
            if (IDCANCEL == i_ret)
            {
                if (IsModified())
                {
                    SetTitle (CString (pco_Doc_->str_Title_.data()) + _T("*"));
                }
            }
            else
            {
                STL_STRING str_ (_T("Unexpected return from CFileDialog::DoModal(). Return value = "));
                str_ += STR_IToStr (i_ret);
                str_ += _T(".");
                ERROR_TRACE (str_);
                AfxMessageBox (_T("Unexpected error. Document may not be saved correctly"), 
                               MB_ICONEXCLAMATION);
            }
        }

    }   while (b_continue);
    
}   //  OnFileSaveAs()
Example #8
0
std::string StructuredScript::Nodes::EchoNode::str_(IAny::Ptr value, IStorage *storage, IExceptionManager *exception, INode *expr){
	value = value->base();
	if (value == nullptr || Query::Object::isUndefined(value) || Query::Object::isExpansion(value) || Query::Object::isExpanded(value)){
		Query::ExceptionManager::set(exception, PrimitiveFactory::createString(Query::ExceptionManager::combine(
			"Cannot echo an invalid object!", expr)));

		return "";
	}

	auto enumObject = dynamic_cast<IEnum *>(value.get());
	if (enumObject != nullptr)
		return enumObject->name();

	auto arrayObject = dynamic_cast<IArrayObject *>(value.get());
	if (arrayObject != nullptr){
		std::string str;
		for (auto entry : arrayObject->list()){
			auto entryStr = str_(entry.value, storage, exception, expr);
			if (Query::ExceptionManager::has(exception))
				return "";

			if (str.empty())
				str = entryStr;
			else
				str += ", " + entryStr;
		}

		return ("[" + str + "]");
	}

	auto rangeObject = dynamic_cast<IRange *>(value.get());
	if (rangeObject != nullptr)
		return rangeObject->str();

	auto nodeObject = dynamic_cast<INodeObject *>(value.get());
	if (nodeObject != nullptr){
		auto nodeValue = nodeObject->value();
		return (nodeValue == nullptr) ? value->str(storage, exception, expr) : ("`" + nodeValue->str() + "`");
	}

	auto str = value->str(storage, exception, expr);
	if (Query::ExceptionManager::has(exception))
		return "";

	if (dynamic_cast<IString *>(value.get()) != nullptr)
		return ("\"" + str + "\"");
	if (dynamic_cast<Objects::Char *>(value.get()) != nullptr)
		return ("\'" + str + "\'");
	if (dynamic_cast<Objects::UChar *>(value.get()) != nullptr)
		return ("\'" + str + "\'U");
	if (dynamic_cast<Objects::Short *>(value.get()) != nullptr)
		return (str + "H");
	if (dynamic_cast<Objects::UShort *>(value.get()) != nullptr)
		return (str + "UH");
	if (dynamic_cast<Objects::UInt *>(value.get()) != nullptr)
		return (str + "U");
	if (dynamic_cast<Objects::Long *>(value.get()) != nullptr || dynamic_cast<Objects::LDouble *>(value.get()) != nullptr)
		return (str + "L");
	if (dynamic_cast<Objects::ULong *>(value.get()) != nullptr)
		return (str + "UL");
	if (dynamic_cast<Objects::LLong *>(value.get()) != nullptr)
		return (str + "LL");
	if (dynamic_cast<Objects::ULLong *>(value.get()) != nullptr)
		return (str + "ULL");
	if (dynamic_cast<Objects::Float *>(value.get()) != nullptr)
		return (str + "F");

	return str;
}