Exemplo n.º 1
0
Arquivo: main.cpp Projeto: CCJY/coliru
std::ostream& set_separator(std::ostream& os, const custom::sep_impl& manip)
{
    if (!os.bad())
    {
        os.pword(getSeparator()) = new std::string(manip.separator);
        os.register_callback(cleanup, getSeparator());
    }
    
    return os;
}
Exemplo n.º 2
0
Arquivo: main.cpp Projeto: CCJY/coliru
 int sync()
 {
     if (stream.iword(separatorEnabled()))
     {
         void*& p = stream.pword(getSeparator());
         stream << *static_cast<std::string*>(p);
         return 0;
     }
     return stream.rdbuf()->pubsync();
 }
Exemplo n.º 3
0
 virtual void emit(std::ostream &stream, int indent = 0) {
     if (this->size() > 0) {
         T *last = this->back(); // TODO wut?
         for (T *e: *this) {
             e->emit(stream);
             if (e != last) {
                 stream << getSeparator();
             }
         }
     }
 }
/// @todo ALC a better way of doing this will be to check if the url has changed,
/// and call unparse automatically when getUrlParsed/getUrlParsedLen is called
void UrlParser::unparse() {
	m_urlParsed.clear();

	// domain
	m_urlParsed.append( m_url, ( m_authority - m_url ) + m_authorityLen );

	bool isFirst = true;
	for ( auto it = m_paths.begin(); it != m_paths.end(); ++it ) {
		if ( !it->isDeleted() ) {
			if ( isFirst ) {
				isFirst = false;
				if ( it->getSeparator() != '/' ) {
					m_urlParsed.append( "/" );
				}
			}

			m_urlParsed += it->getSeparator();
			m_urlParsed.append( it->getString() );
		}
	}

	if ( m_urlParsed[ m_urlParsed.size() - 1 ] != '/' && m_pathEndChar == '/' ) {
		m_urlParsed += m_pathEndChar;
	}

	isFirst = true;
	for ( auto it = m_queries.begin(); it != m_queries.end(); ++it ) {
		if ( !it->isDeleted() ) {
			if ( isFirst ) {
				isFirst = false;
				m_urlParsed.append( "?" );
			} else {
				m_urlParsed += ( it->getSeparator() == '?' ) ? '&' : it->getSeparator();
			}

			m_urlParsed.append( it->getString() );
		}
	}
}
Exemplo n.º 5
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Set the buffer's size (in data elements)
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void dataHandlerString::setSize(const imbxUint32 elementsNumber)
{
	PUNTOEXE_FUNCTION_START(L"dataHandlerString::setSize");

	if(getSeparator() == 0)
	{
		m_strings.resize(1, L"");
                return;
	}

	m_strings.resize(elementsNumber, L"");

	PUNTOEXE_FUNCTION_END();
}
Exemplo n.º 6
0
ExamplesPreview::ExamplesPreview(int engine, QWidget *parent) : QScrollArea(parent)
{
    setWindowFlags(windowFlags() | Qt::ToolTip);
    setAutoFillBackground(true);

    setFrameStyle(QFrame::Box | QFrame::Plain);
    setFixedSize(300, 300);
    setWidgetResizable(true);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    QWidget *widget = new QWidget(this);
    widget->setFixedWidth(280);
    QVBoxLayout *l = new QVBoxLayout(widget);
    l->setSpacing(0);

    QPalette p(palette());
    p.setColor(QPalette::Window, QColor("#c0daff"));
    setPalette(p);

    static const QStringList filters[ENGINE_MAX] =
    {
        (QStringList() << "*.js"),
        (QStringList() << "*.py")
    };

    QDir dir(":/examples");
    QStringList files = dir.entryList(filters[engine], QDir::NoFilter, QDir::Name);
    QFile f;
    for(int i = 0; i < files.size(); ++i)
    {
        f.setFileName(":/examples/" + files[i]);
        if(!f.open(QIODevice::ReadOnly))
            continue;

        ExamplePreviewItem *prev = new ExamplePreviewItem(files[i], f.readLine(), this);
        connect(prev, SIGNAL(openInEditor(QString)), SIGNAL(openInEditor(QString)));
        connect(prev, SIGNAL(openPreview(QString)),  SIGNAL(openPreview(QString)));

        l->addWidget(prev);
        l->addWidget(getSeparator());

        f.close();
    }
    setWidget(widget);

    connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), SLOT(focusChanged(QWidget*, QWidget*)));
}
Exemplo n.º 7
0
    void MultiListBox::updateColumns()
    {
        size_t countStars = 0;
        size_t lastIndexStar = ITEM_NONE;

        int allColumnsWidth = updateWidthColumns(countStars, lastIndexStar);
        int clientWidth = mClient->getWidth();
        int separatorsWidth = mVectorColumnInfo.empty() ? 0 : (mVectorColumnInfo.size() - 1) * mWidthSeparator;
        int freeSpace = clientWidth - separatorsWidth - allColumnsWidth;
        int starWidth = (countStars != 0 && freeSpace > 0) ? (freeSpace / countStars) : 0;

        mWidthBar = 0;
        for (size_t index = 0; index < mVectorColumnInfo.size(); ++ index)
        {
            ColumnInfo& info = mVectorColumnInfo[index];

            int columnWidth = getColumnWidth(index, freeSpace, countStars, lastIndexStar, starWidth);

            if (mHeaderPlace != nullptr)
            {
                info.item->setCoord(mWidthBar, 0, columnWidth, mClient->getHeight());
            }
            else
            {
                info.item->setCoord(mWidthBar, mHeightButton, columnWidth, mClient->getHeight() - mHeightButton);
            }

            info.button->setCoord(mWidthBar, 0, columnWidth, getButtonHeight());
            info.button->_setInternalData(index);

            mWidthBar += columnWidth;

            // промежуток между листами
            Widget* separator = getSeparator(index);
            if (separator)
            {
                separator->setCoord(mWidthBar, 0, mWidthSeparator, mClient->getHeight());
            }

            mWidthBar += mWidthSeparator;
        }

        redrawButtons();
        updateOnlyEmpty();
    }
Exemplo n.º 8
0
// If the child is absolute, then we do not resolve the child against
// the parent.  This seems to make the most logical sense, even though
// that is not the apparent behaviour of the JDK.
//
// If the parent directory is empty, this is not treated as the current
// working directory, but simply as the empty string.
// This allows this class to be used in URL resolution where the current
// directory has no meaning.
//==============================================================================
String FileSystem::resolve(const String& parent, const String& child) const
{
	String normalizedChild = normalize(child);
	if(isAbsolute(normalizedChild))
	{
		return normalizedChild;
	}
	else
	{
		size_t prefixLen = getPrefixLength(normalizedChild);
		String normalizedParent = normalize(parent);
		const CharType lastChar = normalizedParent[normalizedParent.length()-1];
		if(lastChar == getSeparatorChar())
		{
			return normalizedParent + normalizedChild.substr(prefixLen);
		}
		else
		{
			return normalizedParent + getSeparator() + normalizedChild.substr(prefixLen);
		}
	}
}
Exemplo n.º 9
0
// makeToken {{{
int CLexer::makeToken()
{
    //if(isEOF()) return ILexer::RET_EOF;
    
    CToken* token=NULL;
    int ret = ILexer::RET_NORMAL; 
    // トークンの作成
    while(token == NULL)
    {
        skipBlanks();
        if(isComment())
        {
            skipLine();
            continue;
        }

        if( (token = getEOF()) != NULL){ret = ILexer::RET_EOF; break;}
        if( (token = getEOL()) != NULL){ret = ILexer::RET_EOL; nowLine_++;break;}
        
        // トークン取得開始
        if( (token = getKeyword())    != NULL) break; 
        if( (token = getOperator())   != NULL) break;
        if( (token = getIdentifier()) != NULL) break;
		if( (token = getLiteral('\'',false)) != NULL) break;
        if( (token = getLiteral('"',true))   != NULL) break;
        if( (token = getConstant())   != NULL) break;
        if( (token = getSeparator())  != NULL) break;

        // エラー処理
		onAnalyzeError();
        
    }
    
    topToken_ = token;
    makeTokenRet_ = ret;
    
    return ret;
}
Exemplo n.º 10
0
Arquivo: main.cpp Projeto: CCJY/coliru
 std::ostream& nosep(std::ostream& os)
 {
     cleanup(std::ios_base::erase_event, *os.tie(), getSeparator());
     os.tie(nullptr);
     return os << std::nounitbuf;
 }
Exemplo n.º 11
0
void LLChatHistory::appendMessage(const LLChat& chat, const LLSD &args, const LLStyle::Params& input_append_params)
{
	bool use_plain_text_chat_history = args["use_plain_text_chat_history"].asBoolean();

	llassert(mEditor);
	if (!mEditor)
	{
		return;
	}

	mEditor->setPlainText(use_plain_text_chat_history);

	if (!mEditor->scrolledToEnd() && chat.mFromID != gAgent.getID() && !chat.mFromName.empty())
	{
		mUnreadChatSources.insert(chat.mFromName);
		mMoreChatPanel->setVisible(TRUE);
		std::string chatters;
		for (unread_chat_source_t::iterator it = mUnreadChatSources.begin();
			it != mUnreadChatSources.end();)
		{
			chatters += *it;
			if (++it != mUnreadChatSources.end())
			{
				chatters += ", ";
			}
		}
		LLStringUtil::format_map_t args;
		args["SOURCES"] = chatters;

		if (mUnreadChatSources.size() == 1)
		{
			mMoreChatText->setValue(LLTrans::getString("unread_chat_single", args));
		}
		else
		{
			mMoreChatText->setValue(LLTrans::getString("unread_chat_multiple", args));
		}
		S32 height = mMoreChatText->getTextPixelHeight() + 5;
		mMoreChatPanel->reshape(mMoreChatPanel->getRect().getWidth(), height);
	}

	LLColor4 txt_color = LLUIColorTable::instance().getColor("White");
	LLViewerChat::getChatColor(chat,txt_color);
	LLFontGL* fontp = LLViewerChat::getChatFont();	
	std::string font_name = LLFontGL::nameFromFont(fontp);
	std::string font_size = LLFontGL::sizeFromFont(fontp);	
	LLStyle::Params style_params;
	style_params.color(txt_color);
	style_params.readonly_color(txt_color);
	style_params.font.name(font_name);
	style_params.font.size(font_size);	
	style_params.font.style(input_append_params.font.style);

	std::string prefix = chat.mText.substr(0, 4);

	//IRC styled /me messages.
	bool irc_me = prefix == "/me " || prefix == "/me'";

	// Delimiter after a name in header copy/past and in plain text mode
	std::string delimiter = ": ";
	std::string shout = LLTrans::getString("shout");
	std::string whisper = LLTrans::getString("whisper");
	if (chat.mChatType == CHAT_TYPE_SHOUT || 
		chat.mChatType == CHAT_TYPE_WHISPER ||
		chat.mText.compare(0, shout.length(), shout) == 0 ||
		chat.mText.compare(0, whisper.length(), whisper) == 0)
	{
		delimiter = " ";
	}

	// Don't add any delimiter after name in irc styled messages
	if (irc_me || chat.mChatStyle == CHAT_STYLE_IRC)
	{
		delimiter = LLStringUtil::null;
		style_params.font.style = "ITALIC";
	}

	bool message_from_log = chat.mChatStyle == CHAT_STYLE_HISTORY;
	// We graying out chat history by graying out messages that contains full date in a time string
	if (message_from_log)
	{
		style_params.color(LLColor4::grey);
		style_params.readonly_color(LLColor4::grey);
	}

	if (use_plain_text_chat_history)
	{
		LLStyle::Params timestamp_style(style_params);
		if (!message_from_log)
		{
			LLColor4 timestamp_color = LLUIColorTable::instance().getColor("ChatTimestampColor");
			timestamp_style.color(timestamp_color);
			timestamp_style.readonly_color(timestamp_color);
		}
		mEditor->appendText("[" + chat.mTimeStr + "] ", mEditor->getText().size() != 0, timestamp_style);

		if (utf8str_trim(chat.mFromName).size() != 0)
		{
			// Don't hotlink any messages from the system (e.g. "Second Life:"), so just add those in plain text.
			if ( chat.mSourceType == CHAT_SOURCE_OBJECT && chat.mFromID.notNull())
			{
				// for object IMs, create a secondlife:///app/objectim SLapp
				std::string url = LLSLURL("objectim", chat.mFromID, "").getSLURLString();
				url += "?name=" + chat.mFromName;
				url += "&owner=" + chat.mOwnerID.asString();

				std::string slurl = args["slurl"].asString();
				if (slurl.empty())
				{
				    LLViewerRegion *region = LLWorld::getInstance()->getRegionFromPosAgent(chat.mPosAgent);
				    if(region)
				      {
					LLSLURL region_slurl(region->getName(), chat.mPosAgent);
					slurl = region_slurl.getLocationString();
				      }
				}
				url += "&slurl=" + LLURI::escape(slurl);

				// set the link for the object name to be the objectim SLapp
				// (don't let object names with hyperlinks override our objectim Url)
				LLStyle::Params link_params(style_params);
				link_params.color.control = "HTMLLinkColor";
				link_params.link_href = url;
				mEditor->appendText("<nolink>" + chat.mFromName + "</nolink>"  + delimiter,
									false, link_params);
			}
			else if ( chat.mFromName != SYSTEM_FROM && chat.mFromID.notNull() && !message_from_log)
			{
				LLStyle::Params link_params(style_params);
				link_params.overwriteFrom(LLStyleMap::instance().lookupAgent(chat.mFromID));
				// Convert the name to a hotlink and add to message.
				mEditor->appendText(chat.mFromName + delimiter, false, link_params);
			}
			else
			{
				mEditor->appendText(chat.mFromName + delimiter, false, style_params);
			}
		}
	}
	else
	{
		LLView* view = NULL;
		LLInlineViewSegment::Params p;
		p.force_newline = true;
		p.left_pad = mLeftWidgetPad;
		p.right_pad = mRightWidgetPad;

		LLDate new_message_time = LLDate::now();

		if (mLastFromName == chat.mFromName 
			&& mLastFromID == chat.mFromID
			&& mLastMessageTime.notNull() 
			&& (new_message_time.secondsSinceEpoch() - mLastMessageTime.secondsSinceEpoch()) < 60.0
			&& mIsLastMessageFromLog == message_from_log)  //distinguish between current and previous chat session's histories
		{
			view = getSeparator();
			p.top_pad = mTopSeparatorPad;
			p.bottom_pad = mBottomSeparatorPad;
		}
		else
		{
			view = getHeader(chat, style_params);
			if (mEditor->getText().size() == 0)
				p.top_pad = 0;
			else
				p.top_pad = mTopHeaderPad;
			p.bottom_pad = mBottomHeaderPad;
			
		}
		p.view = view;

		//Prepare the rect for the view
		LLRect target_rect = mEditor->getDocumentView()->getRect();
		// squeeze down the widget by subtracting padding off left and right
		target_rect.mLeft += mLeftWidgetPad + mEditor->getHPad();
		target_rect.mRight -= mRightWidgetPad;
		view->reshape(target_rect.getWidth(), view->getRect().getHeight());
		view->setOrigin(target_rect.mLeft, view->getRect().mBottom);

		std::string widget_associated_text = "\n[" + chat.mTimeStr + "] ";
		if (utf8str_trim(chat.mFromName).size() != 0 && chat.mFromName != SYSTEM_FROM)
			widget_associated_text += chat.mFromName + delimiter;

		mEditor->appendWidget(p, widget_associated_text, false);
		mLastFromName = chat.mFromName;
		mLastFromID = chat.mFromID;
		mLastMessageTime = new_message_time;
		mIsLastMessageFromLog = message_from_log;
	}

	if (chat.mNotifId.notNull())
	{
		LLNotificationPtr notification = LLNotificationsUtil::find(chat.mNotifId);
		if (notification != NULL)
		{
			LLIMToastNotifyPanel* notify_box = new LLIMToastNotifyPanel(
					notification, chat.mSessionID);
			//we can't set follows in xml since it broke toasts behavior
			notify_box->setFollowsLeft();
			notify_box->setFollowsRight();
			notify_box->setFollowsTop();

			ctrl_list_t ctrls = notify_box->getControlPanel()->getCtrlList();
			S32 offset = 0;
			// Children were added by addChild() which uses push_front to insert them into list,
			// so to get buttons in correct order reverse iterator is used (EXT-5906) 
			for (ctrl_list_t::reverse_iterator it = ctrls.rbegin(); it != ctrls.rend(); it++)
			{
				LLButton * button = dynamic_cast<LLButton*> (*it);
				if (button != NULL)
				{
					button->setOrigin( offset,
							button->getRect().mBottom);
					button->setLeftHPad(2 * HPAD);
					button->setRightHPad(2 * HPAD);
					// set zero width before perform autoResize()
					button->setRect(LLRect(button->getRect().mLeft,
							button->getRect().mTop, button->getRect().mLeft,
							button->getRect().mBottom));
					button->setAutoResize(true);
					button->autoResize();
					offset += HPAD + button->getRect().getWidth();
					button->setFollowsNone();
				}
			}

			LLTextEditor* text_editor = notify_box->getChild<LLTextEditor>("text_editor_box", TRUE);
			S32 text_heigth = 0;
			if(text_editor != NULL)
			{
				text_heigth = text_editor->getTextBoundingRect().getHeight();
			}

			//Prepare the rect for the view
			LLRect target_rect = mEditor->getDocumentView()->getRect();
			// squeeze down the widget by subtracting padding off left and right
			target_rect.mLeft += mLeftWidgetPad + mEditor->getHPad();
			target_rect.mRight -= mRightWidgetPad;
			notify_box->reshape(target_rect.getWidth(),
					notify_box->getRect().getHeight());
			notify_box->setOrigin(target_rect.mLeft, notify_box->getRect().mBottom);

			if (text_editor != NULL)
			{
				S32 text_heigth_delta =
						text_editor->getTextBoundingRect().getHeight()
								- text_heigth;
				notify_box->reshape(target_rect.getWidth(),
								notify_box->getRect().getHeight() + text_heigth_delta);
			}

			LLInlineViewSegment::Params params;
			params.view = notify_box;
			params.left_pad = mLeftWidgetPad;
			params.right_pad = mRightWidgetPad;
			mEditor->appendWidget(params, "\n", false);
		}
	}
	else
	{
		std::string message = irc_me ? chat.mText.substr(3) : chat.mText;


		//MESSAGE TEXT PROCESSING
		//*HACK getting rid of redundant sender names in system notifications sent using sender name (see EXT-5010)
		if (use_plain_text_chat_history && gAgentID != chat.mFromID && chat.mFromID.notNull())
		{
			std::string slurl_about = SLURL_APP_AGENT + chat.mFromID.asString() + SLURL_ABOUT;
			if (message.length() > slurl_about.length() && 
				message.compare(0, slurl_about.length(), slurl_about) == 0)
			{
				message = message.substr(slurl_about.length(), message.length()-1);
			}
		}

		if (irc_me && !use_plain_text_chat_history)
		{
			message = chat.mFromName + message;
		}
		
		mEditor->appendText(message, FALSE, style_params);
	}

	mEditor->blockUndo();

	// automatically scroll to end when receiving chat from myself
	if (chat.mFromID == gAgentID)
	{
		mEditor->setCursorAndScrollToEnd();
	}
}
Exemplo n.º 12
0
int main(int argc, char * argv[]) {
	copyright();

	/* check arguments */
	if ( argc != 3 ) {
		printf ( "ERROR: Invalid argements.\n" );
		usage(argv[0]);
		return(EXIT_FAILURE);
	}

	/* get arguments */
	PARAMETER from;
	from.argument = argv[1];
	from.separator = getSeparator(from.argument);

	PARAMETER to;
	to.argument = argv[2];
	to.separator = getSeparator(to.argument);

	/* check separator */

	if ( from.separator == -1 || to.separator == -1 ) {
		printf ( "ERROR: Wrong syntax of the arguments.\n" );
		usage(argv[0]);
		return(EXIT_FAILURE);
	}

	/* check size of the parameters */
	if ( from.separator > SIZE_FILE || strlen(from.argument)-from.separator > SIZE_TEXT ) {
		printf ( "ERROR: The input-argument is not valid. File(%d) or text(%d) to long.\n", SIZE_FILE, SIZE_TEXT );
		return(EXIT_FAILURE);
	}
	if ( to.separator > SIZE_FILE || strlen(to.argument)-to.separator-1 > SIZE_TEXT ) {
		printf ( "ERROR: The input-argument is not valid. File(%d) or text(%d) to long.\n", SIZE_FILE, SIZE_TEXT );
		return(EXIT_FAILURE);
	}

	/* analyze arguments */
	memcpy(from.file, from.argument, from.separator);
	from.file[from.separator] = '\0';
	memcpy(from.text, from.argument+from.separator+1, strlen(from.argument)-from.separator);

	memcpy(to.file, to.argument, to.separator);
	to.file[to.separator] = '\0';
	memcpy(to.text, to.argument+to.separator+1, strlen(to.argument)-to.separator);

	printf ( "%s[%s] ==> %s[%s]\n", from.file, from.text, to.file, to.text );

	/* check files */
	if ( !fileExists(from.file) ) {
		printf ( "ERROR: Inputfile doesn't exists.\n" );
		return (EXIT_FAILURE);
	}

	if ( fileExists(to.file) ) {
		printf ( "ERROR: Outputfile already exists.\n" );
		return (EXIT_FAILURE);
	}

	/* read and write line by line */
	char line[SIZE_LINE+1];
	FILE *f = fopen(from.file, "r");
	FILE *t = fopen(to.file, "w");

	while ( fgets (line, sizeof(line), f ) != NULL ) {
		replace(line, from.text, to.text);
		fputs ( line, t);
	}

	fclose(t);
	fclose(f);






	return(EXIT_SUCCESS);
}
Exemplo n.º 13
0
	ItemListSeparator *getFooterSeparator() const { return getSeparator(footerSeparator); }
Exemplo n.º 14
0
	ItemListSeparator *getHeaderSeparator() const { return getSeparator(headerSeparator); }